Take three numbers from the user and print the greatest number.
Solution:
package w3;
import java.util.Scanner;
public class EX3 {
public static void main(String[] args) {
Scanner pass = new Scanner(System.in);
System.out.print("Enter first number : ");
int x = pass.nextInt();
System.out.print("Enter 2nd number : ");
int y = pass.nextInt();
System.out.print("Enter 3rd number : ");
int z = pass.nextInt();
if(x>y && x>z) {
System.out.println("The Greatesr : "+x);
}
else if(y>x && y>z) {
System.out.println("The Greatesr : "+y);
}
else if(z>x && z>y) {
System.out.println("The Greatesr : "+z);
}
else{
System.out.println("Error");}
}
}
Solution:
package w3;
import java.util.Scanner;
public class EX3 {
public static void main(String[] args) {
Scanner pass = new Scanner(System.in);
System.out.print("Enter first number : ");
int x = pass.nextInt();
System.out.print("Enter 2nd number : ");
int y = pass.nextInt();
System.out.print("Enter 3rd number : ");
int z = pass.nextInt();
if(x>y && x>z) {
System.out.println("The Greatesr : "+x);
}
else if(y>x && y>z) {
System.out.println("The Greatesr : "+y);
}
else if(z>x && z>y) {
System.out.println("The Greatesr : "+z);
}
else{
System.out.println("Error");}
}
}
Comments
Post a Comment