In this Java programming tutorial, we'll be exploring how to find the greater of two numbers. This simple yet fundamental task is essential for any programmer, and we'll demonstrate different methods to achieve this goal.
Code:
import java.util.*;
public class Greater {
public static void compare(int a, int b) {
if (a == b) {
System.out.println("Both are equal");
} else if (a > b) {
System.out.println(a);
} else {
System.out.println(b);
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter two numbers: ");
int a = sc.nextInt();
int b = sc.nextInt();
compare(a, b);
}
}
Output:
Enter two numbers:
20 30
30
Related Links:
sign in process initialization failure fix
define a class to declare a character array of size 10 accept the character into the array
design a java program to create to display your name, branch with your college name?
write a java program to display your name and roll number on the terminal
0 Comments
Ask Your Queries in the comments