JAVA 1.2 To find the largest among three numbers x, y, and z.

import java.util.Scanner;
public class Exercise{
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;
if(x >= y && x >= z)
        {
            result=x;
        }
        else if(y >= z)
        {
            result=y;
        }
        else
        {
            result=z;
        }
System.out.println(result);
 }
}

No comments:

Post a Comment