I have an assignment where I have to print each digit while using a for loop and I am very confused. I know that the code I have written is VERY wrong for many reasons, but I'm having a lot of trouble piecing together the various skills we have been learning. How can I fix my code so that 365 is printed as 3 6 5?
class Main {
method1(365);
public static void main(String[] args) {
}
String number = String.valueOf(num);
public int method1(int num) {
for (int i = 0; i < number.length(); i++) {
int j = Character.digit(number.charAt(i), 10);
System.out.print("digit: " + j);
}
}
}