// random numbers: generating pseudo-random numbers in java and testing them // using conditional expressions public class conditional_expressions2 { public static void main(String[] args) { int result; // make this a number from 1 - 100 result = 1 + (int) (Math.random() * 100); //print out whether it is even or odd System.out.println((result%2 == 0) ? result + " is " + " even." : result + " is odd."); // here the lines are broken up to fit on the page better: // print out whether it is divisible by 5 System.out.println((result%5 == 0) ? result + " is divisible " + " by 5." : result + " is not divisible by 5."); // print out whether it is less than 50 System.out.println((result<50 ) ? result + " is less than " + " 50." : result + " is more than 49."); // print out whether it is more than 10 System.out.println((result>10 ) ? result + " greater than 10." : result + " is 10 or less."); System.exit (0); } }