Computer Science, asked by satyam7817, 10 months ago

explain data input technique in a program using the scanner class​

Answers

Answered by irakhedkar
9

import java.util.*; //to import the package util which contains scanner class

class Program{

public static void main(String args[]){

Scanner in = new Scanner(System.in); //to create an object of Scanner class

System. out. println("Enter a number");

int n = in. nextInt(); // input statement for integers

System. out. println("Enter a word");

String s = in.next(); // in. nextLine() can also be used

System.out. println("Enter a letter");

char ch = in.next(). charAt(0); //input statement for a single letter

}

}

Hope this helps,

ira.

the spaces given by me are due to some errors in the site itself

Answered by jyotirajranjan76
0

Answer:

The data entered by the user through the keyboard is provided to our Java program with the help of standard input stream that is specified as System.in in the program. We connect our Scanner class to this stream while creating its object. The input received by Scanner class is broken into tokens using a delimiter pattern. The default delimiter is whitespace. Scanner class provides various next methods to read these tokens from the stream. The different next methods provided by Scanner class are next(), nextShort(), nextInt(), nextLong(), nextFloat(), nextDouble(), nextLine(), next().charAt(0).

Explanation:

I hope it will help!

Similar questions