INPUT IN JAVA
CHAPTER - 4
COMMENT
Non-executable statement
Types of Comment
1. Single Line Comment //
2. Multi line Comment /* …………. */
3. Documentation Comment /**
……………….. */
INPUT IN JAVA
1. Input by using Assignment
2. Input by using Function Argument
3. Input by using Scanner Class
4. Input by using InputStreamReader
INPUT BY USING ASSIGNMENT METHOD
INPUT BY USING FUNCTION ARGUMENT
INPUT BY USING FUNCTION ARGUMENT
INPUT USING SCANNER CLASS
● Latest development in Java
● Scanner class is a built-in class in JDK 1.5
● Scanner class is present in java.util package.
Import a System class
in Program
import java.util.Scanner;
Or
import java.util.*;
SCANNER CLASS
Scanner in=new Scanner(System.in);
o System.in : used to allow the program to receive data
from the keyboard.
o Scanner class works based on Token
o Each token/input can be separated by a blank space
or enter key.
o Other separator/ delimiters are . , ; ? ! White space
SCANNER CLASS METHODS
1. nextShort( )
2. nextInt( )
3. nextFloat( )
4. nextDouble( )
5. nextLong( )
6. next( ) - to accept a word
7. nextLine( ) -to accept a sentence
8. next.charAt(0) - to accept a character
Java program using
Scanner Class
TYPES OF ERRORS
1. Syntax Error
2. Logical Error
3. Run time Error