← all problems

Split a two-digit number 🌶️

The variable number holds a two-digit whole number. The two locked lines at the bottom print a variable named tens and then a variable named ones, which you have to create. Write the code in the box that declares each one as an int: tens should be the digit in the tens place (47 has a 4 there) and ones the digit in the ones place (47 has a 7). Use the / and % operators! Your code will be tested with several different numbers.

Main.java — the program frame below is already written; you're only completing the code in the editable box. Your code will be run several times, each with different starting values for the variables at the top.

public class Main {
    public static void main(String[] args) {
        int number = 47;
        // ---- write your code below ----
        System.out.println(tens);
        System.out.println(ones);
    }
}