Greater number program in Java

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.

What is scanner function?

Scanner function is use to take the input from user in java.

How program will work?

Program of finding the greater number 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.");
			}
		}
	}

Output:


	ENTER THE FIRST NUMBER:- 5
	ENTER THE SECOND NUMBER:- 4
	4 IS GREATER NUMBER.

Advertisment

Post Your Comment