3. Write a Java program that takes three numbers from the user and prints the greatest number.
package HelloWorld;
import java.util.Scanner;
public class LearningJava {
public static void main(String[] args) {
// 3. Write a Java program that takes three numbers from the user
// and prints the greatest number.
Scanner scan = new Scanner(System.in);
int a = scan.nextInt();
int b = scan.nextInt();
int c = scan.nextInt();
if (a>b && a>c){
System.out.print("a is greater");
}
else if (b>a && b>c){
System.out.print("b is greater");
}
else if (c>a && c>b){
System.out.print("c is greater");
}
else {
System.out.print("Invalid Input");
}
}
}
ise ham bina else ke bhi bna skte hai
Uski code
import java.util.Scanner;
public class LearningJava {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int a = scan.nextInt();
int b = scan.nextInt();
int c = scan.nextInt();
if (a > b && a > c) {
System.out.print("a is greater");
}
if (b > a && b > c) {
System.out.print("b is greater");
}
if (c > a && c > b) {
System.out.print("c is greater");
}
}
}
Comments
Post a Comment