Sunday, 23 August 2020

JAVA PROGRAMMING FOR ADDITION OF NUMBERS USER INPUT

 USER INPUT ADDITION
IN JAVA

  • ELEMENTS OF JAVA USED IN PROGRAMMING-:

  • int ---> This command helps you to specify that the value assigned to a particular variable in the specific program is an INTEGER.                                    NOTE-: Here you can also use "byte" that is used to specify that the variable is a number but the value that it can contain is much smaller than "int" command.               
  • import--->This command helps you to import a specific file from setup that was pre-prepared by java to help user to use it's properties .                                             
  • System.out.print-:  This command prints the specified variable or the statement enclosed  by the user.                    
  • [ ; ] ----> This particular ( symbol enclosed in square brackets ) i.e semicolon in java represents that a particular statement written by you is complete. 

  • NOTE-:
  1. CASE of the letter must not be ignored.
  2. After end of every statement remember to close it with semicolon sign i.e ;
  3. None of the special characters should be ignored.

  • PROGRAMMING-:
    package userInput;

    import java.util.Scanner; 


     public class ScannerUserInput {


public static void main(String[] args) {

Scanner sc= new Scanner(System.in);

int  x= sc.nextInt();

int  y= sc.nextInt();

int  sum=x+y ;

System.out.println(sum);

sc.close();


}


}

NOTE-:Here you may add as many integers that the user needs to add.

NOTE-: The set-up that we import here is Scanner file and the name of the set-up file is "java.util.Scanner "it is a type of set-up file that helps user to input data .

  • PROGRAMMING IMAGE-:

  • INPUT & OUTPUT IMAGE IN CONSOLE-:
     Output-1

    Output-2

NOTE-:  As you enter the first number in the console press the "Enter key", by doing this the computer automatically assigns the entered value to the first variable that you specified in the above programming . Now when you enter the second number and do the same, it is assigned the second variable. 

 Here in Output-1
          x is assigned with value of "5"
      y is assigned with value of "6"

   In Output-2
          x is assigned with value of "25"
     y is assigned with value of "25"


THANK YOU😌

FOR VISITING

PLEASE DO FOLLOW OUR PAGE 👦







No comments:

Post a Comment

Popular