import java.util.Scanner; public class BooleanExpression2 { public static void main(String[] args) { /*Question 5.What is the output of the code in (a) and (b) if number is 30? What if number is 35? if (number % 2 == 0) System.out.println(number + " is even."); System.out.println(number + " is odd."); (a) if (number % 2 == 0) System.out.println(number + " is even."); else System.out.println(number + " is odd."); (b) */ Scanner scanner = new Scanner(System.in); System.out.println("Enter a number: "); int number = scanner.nextInt(); if(number % 2== 0) { System.out.println(number + ": is even"); } else { System.out.println(number + ": is odd"); } } } output: 30 is even and odd 35 is odd
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter