SlideShare a Scribd company logo
•Scanner class is one of the class of Java 
which provides the methods to get inputs. 
•Scanner class is present in java.util package 
so we import this package in our program. 
•We first create an object of Scanner class and 
then we use the methods of Scanner class.
Scanner a = new Scanner(System.in); 
Following are methods of Scanner class: 
•next( ) to input a string 
•nextByte() to input a byte value 
•nextInt( ) to input an integer 
•nextFloat( ) to input a float 
•nextLong( ) for Long Values 
•nextDouble() for double values
import java.util.Scanner; 
class GetInput { 
public static void main(String args[]) { 
int a; 
Scanner in = new Scanner(System.in); 
System.out.println("Enter an integer"); 
a = in.nextInt(); 
System.out.println("You entered integer "+a); 
} }
import java.util.Scanner; 
class GetInput { 
public static void main(String args[]) { 
float b; 
Scanner in = new Scanner(System.in); 
System.out.println("Enter a float"); 
b = in.nextFloat(); 
System.out.println("You entered float "+b); 
} }
import java.util.Scanner; 
class GetInput { 
public static void main(String args[]) { 
String s; 
Scanner in = new Scanner(System.in); 
System.out.println("Enter a string"); 
s = in.nextLine(); 
System.out.println("You entered string"+s); 
} }

More Related Content

PPT
ppt on scanner class
DOCX
Java scanner, everything you need to know about Java Scanner
PPTX
Java input
PPTX
Buffer and scanner
PPT
Scanner class
PPT
Taking User Input in Java
PPTX
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
PPT
Iterator Design Pattern
ppt on scanner class
Java scanner, everything you need to know about Java Scanner
Java input
Buffer and scanner
Scanner class
Taking User Input in Java
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
Iterator Design Pattern

What's hot (18)

PPSX
Dr. Rajeshree Khande - Java Interactive input
PPT
Intro To Scala
PPTX
Files io
PPTX
Introduction to c_plus_plus (6)
PPTX
Python for Security Professionals
PPTX
Java Tutorial Lab 5
PPT
Stream Based Input Output
PPTX
Intro To C++ - Class #18: Vectors & Arrays
PPTX
Getting started with C# Programming
PDF
Functions
PDF
PPTX
PPTX
Iterator - a powerful but underappreciated design pattern
PPTX
Java 8 streams
PDF
Streams in Java 8
PPTX
Java New Programming Features
PDF
PDF
Generic Programming
Dr. Rajeshree Khande - Java Interactive input
Intro To Scala
Files io
Introduction to c_plus_plus (6)
Python for Security Professionals
Java Tutorial Lab 5
Stream Based Input Output
Intro To C++ - Class #18: Vectors & Arrays
Getting started with C# Programming
Functions
Iterator - a powerful but underappreciated design pattern
Java 8 streams
Streams in Java 8
Java New Programming Features
Generic Programming
Ad

Viewers also liked (16)

PDF
java.io - streams and files
PDF
Java lesson khmer
PDF
Learn Java Part 4
PDF
Learn Java Part 5
DOCX
Photoshop project tutorial
PPTX
Music Magazine Analysis
DOCX
Java file
PPTX
El punto
PDF
Approaches_for_planning_the_ISS_cosmonau
DOCX
PPT
Applied statistics manufacturing (1)
PDF
2014-15 Volume 3: December / Holiday
PPTX
Media Storyboard
DOCX
Latihan Matematik
PPTX
Diapo ingles
PPTX
Geometrical tolerance 2014
java.io - streams and files
Java lesson khmer
Learn Java Part 4
Learn Java Part 5
Photoshop project tutorial
Music Magazine Analysis
Java file
El punto
Approaches_for_planning_the_ISS_cosmonau
Applied statistics manufacturing (1)
2014-15 Volume 3: December / Holiday
Media Storyboard
Latihan Matematik
Diapo ingles
Geometrical tolerance 2014
Ad

Similar to Handling inputs via scanner class (20)

PPTX
scan.pptx
PDF
3.Lesson Plan - Input.pdf.pdf
PDF
djkkfhulkgyftfdtrdrsdsjjjjjjjjjjjjjjjjjjj
PPTX
Computer programming 2 chapter 1-lesson 2
DOCX
How to get input from usjer in Java.docx
PPTX
Lab 01jbjbjkbkbjkbkjbkjbkbkjbbnjjkb.pptx
PPTX
Lab 01hhkhkhkhkhkhkhkhkhjjjkhkkhhhhh.pptx
DOCX
All Of My Java Codes With A Sample Output.docx
PPTX
Scannerclass
DOCX
Main Java[All of the Base Concepts}.docx
PPTX
JAVA_SAMPLE CODING, JAVA BASICS PROGRAMS.pptx
PPTX
DSA 103 Object Oriented Programming :: Week 4
PPTX
Reading and writting
PPTX
Wk_10_Scanner and BufferedReader Class in Java.pptx
PPTX
Class IX Input in Java using Scanner Class (1).pptx
PPT
07-Basic-Input-Output.ppt
PPTX
Chapter 3.4
PPTX
Reading and writting v2
PPTX
java input & output statements
scan.pptx
3.Lesson Plan - Input.pdf.pdf
djkkfhulkgyftfdtrdrsdsjjjjjjjjjjjjjjjjjjj
Computer programming 2 chapter 1-lesson 2
How to get input from usjer in Java.docx
Lab 01jbjbjkbkbjkbkjbkjbkbkjbbnjjkb.pptx
Lab 01hhkhkhkhkhkhkhkhkhjjjkhkkhhhhh.pptx
All Of My Java Codes With A Sample Output.docx
Scannerclass
Main Java[All of the Base Concepts}.docx
JAVA_SAMPLE CODING, JAVA BASICS PROGRAMS.pptx
DSA 103 Object Oriented Programming :: Week 4
Reading and writting
Wk_10_Scanner and BufferedReader Class in Java.pptx
Class IX Input in Java using Scanner Class (1).pptx
07-Basic-Input-Output.ppt
Chapter 3.4
Reading and writting v2
java input & output statements

More from simarsimmygrewal (7)

DOCX
DOCX
Java file
DOCX
PPTX
Handling inputs via io..continue
PPTX
Excception handling
PPTX
Type casting
PDF
Wrapper classes
Java file
Handling inputs via io..continue
Excception handling
Type casting
Wrapper classes

Recently uploaded (20)

PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Lesson notes of climatology university.
PPTX
master seminar digital applications in india
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Cell Structure & Organelles in detailed.
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Classroom Observation Tools for Teachers
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Sports Quiz easy sports quiz sports quiz
PDF
Basic Mud Logging Guide for educational purpose
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Cell Types and Its function , kingdom of life
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Microbial diseases, their pathogenesis and prophylaxis
Computing-Curriculum for Schools in Ghana
Lesson notes of climatology university.
master seminar digital applications in india
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Final Presentation General Medicine 03-08-2024.pptx
Anesthesia in Laparoscopic Surgery in India
Cell Structure & Organelles in detailed.
STATICS OF THE RIGID BODIES Hibbelers.pdf
Classroom Observation Tools for Teachers
102 student loan defaulters named and shamed – Is someone you know on the list?
VCE English Exam - Section C Student Revision Booklet
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
TR - Agricultural Crops Production NC III.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Sports Quiz easy sports quiz sports quiz
Basic Mud Logging Guide for educational purpose
Module 4: Burden of Disease Tutorial Slides S2 2025
Cell Types and Its function , kingdom of life
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx

Handling inputs via scanner class

  • 1. •Scanner class is one of the class of Java which provides the methods to get inputs. •Scanner class is present in java.util package so we import this package in our program. •We first create an object of Scanner class and then we use the methods of Scanner class.
  • 2. Scanner a = new Scanner(System.in); Following are methods of Scanner class: •next( ) to input a string •nextByte() to input a byte value •nextInt( ) to input an integer •nextFloat( ) to input a float •nextLong( ) for Long Values •nextDouble() for double values
  • 3. import java.util.Scanner; class GetInput { public static void main(String args[]) { int a; Scanner in = new Scanner(System.in); System.out.println("Enter an integer"); a = in.nextInt(); System.out.println("You entered integer "+a); } }
  • 4. import java.util.Scanner; class GetInput { public static void main(String args[]) { float b; Scanner in = new Scanner(System.in); System.out.println("Enter a float"); b = in.nextFloat(); System.out.println("You entered float "+b); } }
  • 5. import java.util.Scanner; class GetInput { public static void main(String args[]) { String s; Scanner in = new Scanner(System.in); System.out.println("Enter a string"); s = in.nextLine(); System.out.println("You entered string"+s); } }