So this is my code right know. The code works with putting in 123 and I get 6 as answer. But if I put 1 2 3 I get 1 as answer. I want the code to convert into a string, but if I putt a space I will give a error message but don't know how to do it. I have try different things but getting errors every time, so can someone help me out? I still want the code to count the sum of 123 but give a error message, "try again, with no space" if I put 1 2 3 in.
int m, n, sum = 0;
System.out.println("Skriv in de tal som du vill addera");
m = sc.nextInt();
while (m > 0) {
n = m % 10;
sum = sum + n;
m = m / 10;
}
System.out.println("Summan av talen:" + sum);
}