Ticker

6/recent/ticker-posts

JAVA week 1 Program question 2


Java Week 1:Q2 

//Complete the code segment to find the largest among three numbers x, y, and z. You should use if-then-else construct in Java.
import java.util.Scanner; 
public class Exercise1_2 
{
       public static void main(String[] args)
 {
        Scanner s = new Scanner(System.in);
        int x = s.nextInt();
        int y = s.nextInt();
        int z = s.nextInt();
        int result = 0;

/*Use if...else ladder to find the largest among 3 numbers and store the largest number in a variable called result.*/
if((x>y) && (x>z))
 System.out.print(x);
else
if((y>x) && (y>z))
  System.out.print(y);
else
if((z>x)&& (z>y))
System.out.print(z);

}
}

Post a Comment

0 Comments