Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /**
- *
- * @author Hantack
- */
- public class Simulation {
- public int createTail(int n) {
- n *= n; String ns = String.valueOf(n);
- ns = (!(ns.length() % 2 == 0)) ? "0" + ns : ns;
- ns = ns.substring(((ns.length() / 2) - 2), ((ns.length() / 2) + 2));
- System.out.println(ns);
- return Integer.parseInt(ns);
- }
- String input = "";
- public static void main(String[] args) {
- Simulation sim = new Simulation();
- Scanner xr = new Scanner(System.in);
- sim.input = xr.nextLine();
- try {
- int n = Integer.parseInt(sim.input);
- if (n > 999) {
- for (int i = 0; i < 5; i++) {
- n = sim.createTail(n);
- }
- } else {
- System.out.println("Give a valid tail");
- }
- }catch(java.lang.NumberFormatException err){
- System.out.println("Give a value in the range of Integer");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement