Computer Science, asked by justenwistahn, 1 month ago

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 arpitabiswas43615
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 BrainlyProgrammer
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?
  1. object.nextInt()- accepts integer
  2. object.nextLong()- accepts big numbers
  3. object.nextShort()- accept short numbers
  4. object.nextLine()- accepts a sentence
  5. object.next()- accepts word
  6. object.nextFloat()- accept fractional numbers (upto 7 significant digits)
  7. 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