Write the syntax with reference to Java Programming:
i) To accept a word ‘wd’ through scanner class
ii) To accept an integer value ‘p’ through scanner class.
Answers
Answered by
7
Answer:
i) Scanner sc = new Scanner (System.in);
String wd = sc.nextLine();
ii) Scanner sc = new Scanner (System.in);
int p = sc.nextInt();
Answered by
15
Answer:
i) String wd=sc.next();
ii) int p=sc.nextInt();
where sc is a object of Scanner class.
Learn More!!
- How to take input?
- object.nextInt()- accepts integer
- object.nextLong()- accepts big numbers
- object.nextShort()- accept short numbers
- object.nextLine()- accepts a sentence
- object.next()- accepts word
- object.nextFloat()- accept fractional numbers (upto 7 significant digits)
- object.nextDouble()- accepts fractional numbers (upto 15 significant digits)
- Note:- Here "object" is object created for Scanner class
- To create an object of Scanner class, here is the syntax..
Scanner object=new Scanner (System.in);
- You can also create object of a class in similar way..
Class_Name object=new Class_Name();
Similar questions