"KEEP LEARNING, DON'T STOP."
"KEEP LEARNING, DON'T STOP."
In this section you will learn how to find greater number in Java in easy way. We are finding the greater number in program with the help of if else condion.
In this program we are taking the input from the user. We are using scanner function to take the input from user. To take the input from user we will import scanner package in our program.
Scanner function is use to take the input from user in java.
import java.util.Scanner; class GreaterNumber { public static void main(String arg[]) { int a, b; Scanner sc = new Scanner(System.in); System.out.println("ENTER THE FIRST NUMBER:-"); a = sc.nextInt(); System.out.println("ENTER THE SECOND NUMBER:-"); b = sc.nextInt(); if(a>b) { System.out.println(a+" IS GREATER NUMBER."); } else { System.out.println(b+" IS GREATER NUMBER."); } } }
ENTER THE FIRST NUMBER:- 5 ENTER THE SECOND NUMBER:- 4 4 IS GREATER NUMBER.
Advertisment