import java.util.Scanner; class RicMain { public static void main(String[] args) { Scanner ip = new Scanner(System.in); int n, m; System.out.print("Input number: "); n = ip.nextInt(); System.out.printf("%d + %d%d + %d%d%d", n, n, n, n, n, n); m = n + 11*n + 111*n; System.out.println(" = " + m); } }
My problem is, for m = n + 11*n + 111*n, it works for numbers 1 - 9, but for 10 and above, it wont work because for example
if I input 10, it would output: 10 + 1010 + 101010, but for m, it is wrong because 11 * 10 != 1010. So how do I fix this?