Take three numbers from the user and print the greatest number

Share Your Love

Hello guys, welcome to Lingarajtechhub.com Today we are going to discuss how to take three numbers from the user and print the greatest number.

code:

      package com.control.java;
      import java.util.Scanner;

      public class Greatest_number {

      public static void main(String[] args) {
		 int a,b,c;
		 Scanner Sc=new Scanner(System.in);
		 System.out.println("enter the value of a,b,c");
		 a=Sc.nextInt( );
		 b=Sc.nextInt( );
		 c=Sc.nextInt( );
		 
		 if(a>b)
			{
				if(a>c)
			
				System.out.println("a is greater");
			else
				System.out.println("c is greater");
			}
			else
			{
			if(b>c)
				System.out.println("b is greater");
			else
				System.out.println("c is greater");
			
			}	
		}

	}

line-2:

 Package com.control.java 

It is a java package( com.control.java) which is a collection of classes and this package is created in a java project . 

Line-3:

❖ import java.util.Scanner; 

Scanner is a class in java. util package used for obtaining the input of the primitive types like int, double, etc. and strings .

Line-5:

❖ public class Greatest_number {

>>–Here Greatest_number  is defined as a class which is a template used to create objects and to define object data types and methods .

 >–and it’s defined as public because it can be accessed anywhere . 

Line-7:

❖ public static void main(String[] args) 

>>– it is a main method in which we can execute a program //public :it is an access modifier of the main function which must be public so that the JVM which is (Java Virtual Machine)can access and execute this method. 

//If a method is not public, then access is restricted and its showing error //static is a keyword in which main method has must to be static in which JVM can load the class into memory and call the main method without creating an instance //void it means no return type 

//main() is function string[]args : string means collection of characters ,String[] args represents a collection of Strings that are separated by a space and can be typed into the program on the terminal directly 

Line-8:

❖ int a,b,c; 

>>– here we declare a,b,c as a variable which is integer type 

Line-9:

❖ Scanner sc=new Scanner(System.in); 

>>–it means here scanner is a class and Sc is the instance of the object which is new Scanner.System.in is an argument 

Line-10:

❖ System.out.println(“Enter the value of a,b,c “); 

>>– it means System is a class name and out is an instance of the System println is print a new line 

Line-11:

❖ a=sc.nextInt(); 

>>– here a is a variable that we take and Sc is our instance name which is create for a object and nextInt() is a method method of a Scanner object reads in a string of digits or char and converts them into an int type 

Line-12:

❖ b=sc.nextInt(); 

>>– here b is a variable that we take and Sc is our instance name which is created for an object and nextInt() is a method method of a Scanner object that reads in a string of digits or char and converts them into an int type.

Line-13:

❖ c=sc.nextInt(); 

>>– here c is a variable that we take and Sc is our instance name which is create for a object and nextInt() is a method method of a Scanner object reads in a string of digits or char and converts them into an int type 

Line-15:

  • if(a>b)

>>–Here loop started and a is greater than b.

Line-17:

  • if(a>c)

>>–Here a is greater than c.

Line-19:

❖ System.out.println(“a is greater” ); 

>>– it means System is a class name and out is an instance of the System println is print a new line . 

Line-20:

  • Else

>>–loop

Line-21:

❖ System.out.println(“c is greater” ); 

>>– it means System is a class name and out is an instance of the System println is print a new line . 

Line-23:

❖ else

     >>–loop.

Line-25:

  • if(b>c)

>>–Here a is greater than c.

Line-26:

❖ System.out.println(“b is greater” ); 

>>– it means System is a class name and out is an instance of the System println is print a new line . 

Line-27:

  • Else

>>–loop

Line-28:

❖ System.out.println(“c is greater” ); 

>>– it means System is a class name and out is an instance of the System println is print a new line. 

Share Your Love
Avatar photo
SONALIN SAHOO

Myself Sonalin Shaoo. I am quite happy to contribute here some java programming content and my friends Lipsa Mohanty ,Sushil Puhan, Aswin Kumar Nayak also help me to contribute their Opinion on this .

Articles: 40

Newsletter Updates

Enter your email address below to subscribe to our newsletter