0% found this document useful (0 votes)
50 views9 pages

CS 8392 - Oop - Unit - 1 - PPT - 1.5

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views9 pages

CS 8392 - Oop - Unit - 1 - PPT - 1.5

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

CS 8392

OBJECT
ORIENTED
PROGRAMMING

Vasantha Kumar V ,AP/CSE


The Scanner class is used to get user input,
and it is found in the java.util package.

Import the package:


import java.util.Scanner;
Scanner
Create object for the class Scanner:
Scanner myObj = new Scanner(System.in);
Method Description

nextBoolean() Reads a boolean value from the user

nextByte() Reads a byte value from the user

nextDouble() Reads a double value from the user

Input Types nextFloat() Reads a float value from the user

nextInt() Reads a int value from the user

nextLine() Reads a String value from the user

nextLong() Reads a long value from the user

nextShort() Reads a short value from the user


import java.util.Scanner;

class MyClass {
public static void main(String[] args) {
Example Scanner myObj = new Scanner(System.in);
System.out.println("Enter name");
String name = myObj.nextLine();
System.out.println("Name: " + name);
Import the package:

BufferedReader + import java.io.BufferedReader;


InputStreamReader import java.io.InputStreamReader;
Example
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Demo{
public static void main(String[] args) throws IOException{
BufferedReader my_reader = new BufferedReader(new
InputStreamReader(System.in));
String my_name = my_reader.readLine();
System.out.println("The name is ");
System.out.println(my_name);
}
Import the package:
import java.io.Console;
System.console
Create object for the class Scanner:
Console console = System.console();
import java.io.Console;

public class JavaConsole {

public static void main(String[] args) {


Example Console console = System.console();

String input = console.readLine();


System.out.println("input : " + input);
} }
}
THANK YOU

You might also like