Download presentation
Presentation is loading. Please wait.
Published byAldous Green Modified over 8 years ago
2
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter 1st Value: "); num1=input.nextInt(); System.out.println(“Number Entered = " + num1); }
3
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter 1st Value: "); num1=input.nextInt(); System.out.println(“Number Entered = " + num1); } This the Package which contain the classes for getting input from the user
4
Import is used to include external packages in your code import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter 1st Value: "); num1=input.nextInt(); System.out.println(“Number Entered = " + num1); }
5
Here we are creating an object of the Scanner class that we have imported in out java code… where input is name of the object… by the help of this input object we are going to take input from the users. import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter 1st Value: "); num1=input.nextInt(); System.out.println(“Number Entered = " + num1); }
6
new reserved word is used to create an object of the class… import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter 1st Value: "); num1=input.nextInt(); System.out.println(“Number Entered = " + num1); }
7
System.in is an input stream import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter 1st Value: "); num1=input.nextInt(); System.out.println(“Number Entered = " + num1); }
8
input.nextInt() would take the input from the user and would assign it to a variable num1. import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter 1st Value: "); num1=input.nextInt(); System.out.println(“Number Entered = " + num1); } }
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.