63.0k views
0 votes
in Java, Write an expression that will print "Even" if the value of userNum is an even number. Hint: Use the % operator. Also, be sure to use ==, and not just =.

User Nick Swan
by
7.9k points

1 Answer

7 votes

Answer:

public class Main {

public static void main(String[] args) {

int userNum = 64;

int secondvar = 32;

int thirdvar = userNum % secondvar;

int fourthvar = userNum / secondvar;

if (thirdvar == 0) {

System.out.println("Even, remainder is, " + fourthvar);

} else {

System.out.println("Not even, remainder is " + fourthvar);

}

}

}

Step-by-step explanation:

This should work, you can also test it in an online compiler.

Change the numbers in userNum and secondvar for different outputs.

User SPandya
by
7.3k points