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-:
- CASE of the letter must not be ignored.
- After end of every statement remember to close it with semicolon sign i.e ;
- 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 .
No comments:
Post a Comment