Use Of Scanner Class For Reading Input Form Keyboard By Users.

Program To Input Or Read And Print Roll No. , Name and Percentage Marks For A Student Using Scanner Class.
\\ If you have any query or questions on my post then please comment below //
Why we use Input Stream ?
Input Stream class defines the following methods for reading bytes :
int read() throws IOException
int read(byte b[]) throws IOException
int read(byte b[], int offset, int length) throws IOException

Scanner Class : The Scanner Class is a class used for "scanning" primitive types and Strings.It can be used to get input from an Input Stream , to parse through a string of text or to read from a file.

Syntax :
1. The following code snippet shows how to read an integer from the keyboard :

                      Scanner scanner=new Scanner(System.in);
                      int i = scanner.nextInt();
               

2. The following code snippet shows how to read a String from the keyboard :

                       String S;
                       Scanner scanner=new Scanner(System.in);
                       System.out.println("Enter a string");
                       S=scanner.next();  
Program
 import java.io.*;
import java util.*;
class Scan
{
 public static void main(String args[]) throws IOException
{
Scanner obj=new Scanner(System.in);
int rno;
String name;
float percentage;
System.out.println("Enter a Roll No.");
rno= obj.nextInt();
System.out.println("Enter a Name");
name=obj.next();
System.out.println("Enter a percentage marks");
percentage=obj.nextFloat();
System.out.println("Roll No."+ rno);
System.out.println("Name"+ name);
System.out.println("Percentage Marks"+ percentage);
obj.close();    
}
Output
Roll No. 1
Name Amir Khan
Percentage Marks 87% 
 
Expert Review: This program will help you to read the input given by the users from keyboard as there are many methods but this method is the best and simplest , easy code as well as shorter codes which will be eas for you to remeber.

Click Here To Know How To Download Above Video Tutorials Or YouTube Videos Free


 Enter Your Email Id To Get Our Programming, Web Development, Video Tutorial, Job Updates In Mail :

Labels: ,