code:
public static void main(String[] args) { ConsoleInputManager in = new ConsoleInputManager(); ConsoleOutputManager out = new ConsoleOutputManager(); int n = in.readInt(); int somma = 0, i ; for ( i = 1; n > 0; i = i + 2){ somma +=i*i; n--; } out.println(somma); }
code:
public static void main(String[] args) { ConsoleInputManager in = new ConsoleInputManager(); int n = in.readInt(); int quadrato; int m; String s = String.valueOf(n); String squad; System.out.println(s); int lung = s.length(); for(int i = 1; i < 10 ; i++){ squad = s.substring(1,3); m = Integer.parseInt(squad); quadrato = m*m; System.out.println(quadrato); s = String.valueOf(quadrato); lung = s.length(); s = (lung == 3)? "0"+s:s; s = (lung == 2)? "00"+s:s; s = (lung == 1)? "000"+s:s; } }