It is a sample Java program try to explain each command line

It is a sample Java program, try to explain each command line briefly what does it do in a comment after code//(x) Program user enters these values: 3 & 17, write out the EXACT output of this program PAY ATTENTION that user will enter integer values 3 & 17 for local variables n1 & n2

Solution

Import Java.util.Scanner

Imports java library for scanning the input from STDIN

public class FirstProgram

Defines a class FirstProgram which is visible across all the assemblies.

No it should be

public static void main(String[] args)

System.out.println(“Hello out there!”)

Prints Hello out there! to the console.

System.out.print(“I will add two numbers for you.”)

Prints I will add two numbers for you. to the console.

int n1,n2 //Declares two integer variables naming n1 and n2

Scanner k = new Scanner(System.in);

//Declares and Defines a Scanner variable named k which will help us to take input from Console.

System.out.print(“Enter first integer value : ”)

Prints Enter first integer value : to the console.

n1 = k.nextInt()

//Get next integer from the Console and assign it to n1

System.out.print(“Enter second integer value : ”)

Prints Enter second integer value : to the console.

n2 = k.nextInt()

//Get next integer from the Console and assign it to n2

int s = n1+n2;

//Adds n1 and n2 and assign it to s

System.out.print(“Two entered # are: “+n1+”,” + n2+”\ The sum is: ”);

Prints Two entered # are 3,17

The sum is:

System.out.print(n1+n2);

Prints 20

System.out.print(“\ The sum is = ”+s);

Prints The sum is = 20

 It is a sample Java program, try to explain each command line briefly what does it do in a comment after code//(x) Program user enters these values: 3 & 17
 It is a sample Java program, try to explain each command line briefly what does it do in a comment after code//(x) Program user enters these values: 3 & 17

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site