SlideShare a Scribd company logo
1 of 5
Download to read offline
•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

What's hot

Dr. Rajeshree Khande - Java Interactive input
Dr. Rajeshree Khande - Java Interactive inputDr. Rajeshree Khande - Java Interactive input
Dr. Rajeshree Khande - Java Interactive inputjalinder123
 
Intro To Scala
Intro To ScalaIntro To Scala
Intro To Scalachambeda
 
Introduction to c_plus_plus (6)
Introduction to c_plus_plus (6)Introduction to c_plus_plus (6)
Introduction to c_plus_plus (6)Sayed Ahmed
 
Python for Security Professionals
Python for Security ProfessionalsPython for Security Professionals
Python for Security ProfessionalsAditya Shankar
 
Java Tutorial Lab 5
Java Tutorial Lab 5Java Tutorial Lab 5
Java Tutorial Lab 5Berk Soysal
 
Stream Based Input Output
Stream Based Input OutputStream Based Input Output
Stream Based Input OutputBharat17485
 
Intro To C++ - Class #18: Vectors & Arrays
Intro To C++ - Class #18: Vectors & ArraysIntro To C++ - Class #18: Vectors & Arrays
Intro To C++ - Class #18: Vectors & ArraysBlue Elephant Consulting
 
Getting started with C# Programming
Getting started with C# ProgrammingGetting started with C# Programming
Getting started with C# ProgrammingBhushan Mulmule
 
Iterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design patternIterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design patternNitin Bhide
 
Java New Programming Features
Java New Programming FeaturesJava New Programming Features
Java New Programming Featurestarun308
 

What's hot (18)

Dr. Rajeshree Khande - Java Interactive input
Dr. Rajeshree Khande - Java Interactive inputDr. Rajeshree Khande - Java Interactive input
Dr. Rajeshree Khande - Java Interactive input
 
Intro To Scala
Intro To ScalaIntro To Scala
Intro To Scala
 
Files io
Files ioFiles io
Files io
 
Introduction to c_plus_plus (6)
Introduction to c_plus_plus (6)Introduction to c_plus_plus (6)
Introduction to c_plus_plus (6)
 
Python for Security Professionals
Python for Security ProfessionalsPython for Security Professionals
Python for Security Professionals
 
Java Tutorial Lab 5
Java Tutorial Lab 5Java Tutorial Lab 5
Java Tutorial Lab 5
 
Stream Based Input Output
Stream Based Input OutputStream Based Input Output
Stream Based Input Output
 
Intro To C++ - Class #18: Vectors & Arrays
Intro To C++ - Class #18: Vectors & ArraysIntro To C++ - Class #18: Vectors & Arrays
Intro To C++ - Class #18: Vectors & Arrays
 
Getting started with C# Programming
Getting started with C# ProgrammingGetting started with C# Programming
Getting started with C# Programming
 
Functions
FunctionsFunctions
Functions
 
Java8
Java8Java8
Java8
 
Io streams
Io streamsIo streams
Io streams
 
Iterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design patternIterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design pattern
 
Java 8 streams
Java 8 streamsJava 8 streams
Java 8 streams
 
Streams in Java 8
Streams in Java 8Streams in Java 8
Streams in Java 8
 
Java New Programming Features
Java New Programming FeaturesJava New Programming Features
Java New Programming Features
 
Iterator
IteratorIterator
Iterator
 
Generic Programming
Generic ProgrammingGeneric Programming
Generic Programming
 

Viewers also liked

java.io - streams and files
java.io - streams and filesjava.io - streams and files
java.io - streams and filesMarcello Thiry
 
Java lesson khmer
Java lesson khmerJava lesson khmer
Java lesson khmerUl Sovanndy
 
Photoshop project tutorial
Photoshop project tutorialPhotoshop project tutorial
Photoshop project tutorialmeyrni-ahmed
 
Music Magazine Analysis
Music Magazine AnalysisMusic Magazine Analysis
Music Magazine AnalysisCloee Lang
 
Approaches_for_planning_the_ISS_cosmonau
Approaches_for_planning_the_ISS_cosmonauApproaches_for_planning_the_ISS_cosmonau
Approaches_for_planning_the_ISS_cosmonauNail Khusnullin
 
2014-15 Volume 3: December / Holiday
2014-15 Volume 3: December / Holiday2014-15 Volume 3: December / Holiday
2014-15 Volume 3: December / HolidayMBHS_SandS
 
Media Storyboard
Media StoryboardMedia Storyboard
Media StoryboardCloee Lang
 
Diapo ingles
Diapo inglesDiapo ingles
Diapo inglesjemsen
 

Viewers also liked (16)

java.io - streams and files
java.io - streams and filesjava.io - streams and files
java.io - streams and files
 
Java lesson khmer
Java lesson khmerJava lesson khmer
Java lesson khmer
 
Learn Java Part 4
Learn Java Part 4Learn Java Part 4
Learn Java Part 4
 
Learn Java Part 5
Learn Java Part 5Learn Java Part 5
Learn Java Part 5
 
Photoshop project tutorial
Photoshop project tutorialPhotoshop project tutorial
Photoshop project tutorial
 
Music Magazine Analysis
Music Magazine AnalysisMusic Magazine Analysis
Music Magazine Analysis
 
Java file
Java fileJava file
Java file
 
El punto
El puntoEl punto
El punto
 
Approaches_for_planning_the_ISS_cosmonau
Approaches_for_planning_the_ISS_cosmonauApproaches_for_planning_the_ISS_cosmonau
Approaches_for_planning_the_ISS_cosmonau
 
C++ file
C++ fileC++ file
C++ file
 
Applied statistics manufacturing (1)
Applied statistics manufacturing (1)Applied statistics manufacturing (1)
Applied statistics manufacturing (1)
 
2014-15 Volume 3: December / Holiday
2014-15 Volume 3: December / Holiday2014-15 Volume 3: December / Holiday
2014-15 Volume 3: December / Holiday
 
Media Storyboard
Media StoryboardMedia Storyboard
Media Storyboard
 
Latihan Matematik
Latihan MatematikLatihan Matematik
Latihan Matematik
 
Diapo ingles
Diapo inglesDiapo ingles
Diapo ingles
 
Geometrical tolerance 2014
Geometrical tolerance 2014Geometrical tolerance 2014
Geometrical tolerance 2014
 

Similar to Handling inputs via scanner class

Java Programs
Java ProgramsJava Programs
Java Programsvvpadhu
 
Prompt a user to enter a series of integers separated by spaces and .pdf
Prompt a user to enter a series of integers separated by spaces and .pdfPrompt a user to enter a series of integers separated by spaces and .pdf
Prompt a user to enter a series of integers separated by spaces and .pdfFootageetoffe16
 
Write a program, Loopy2, that uses a loop to collect an arbitrary nu.pdf
Write a program, Loopy2, that uses a loop to collect an arbitrary nu.pdfWrite a program, Loopy2, that uses a loop to collect an arbitrary nu.pdf
Write a program, Loopy2, that uses a loop to collect an arbitrary nu.pdfsivakumar19810
 
In JAVA! Write the program that will do the following tasks- Declare.docx
In JAVA!  Write the program that will do the following tasks- Declare.docxIn JAVA!  Write the program that will do the following tasks- Declare.docx
In JAVA! Write the program that will do the following tasks- Declare.docxcarold12
 
Write a java program that reads a numbers of scores and displays its m.docx
Write a java program that reads a numbers of scores and displays its m.docxWrite a java program that reads a numbers of scores and displays its m.docx
Write a java program that reads a numbers of scores and displays its m.docxlez31palka
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsMuhammadTalha436
 
JAVA Question : Programming Assignment
JAVA Question : Programming AssignmentJAVA Question : Programming Assignment
JAVA Question : Programming AssignmentCoding Assignment Help
 
Chap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptxChap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptxchetanpatilcp783
 
program for remove unnecessary space from a given input string.imp.pdf
program for remove unnecessary space from a given input string.imp.pdfprogram for remove unnecessary space from a given input string.imp.pdf
program for remove unnecessary space from a given input string.imp.pdfannaistrvlr
 
Java Programs Lab File
Java Programs Lab FileJava Programs Lab File
Java Programs Lab FileKandarp Tiwari
 
Throwing.javaimport java.util.InputMismatchException; import jav.pdf
Throwing.javaimport java.util.InputMismatchException; import jav.pdfThrowing.javaimport java.util.InputMismatchException; import jav.pdf
Throwing.javaimport java.util.InputMismatchException; import jav.pdfaquazac
 
Lec 5 13_aug [compatibility mode]
Lec 5 13_aug [compatibility mode]Lec 5 13_aug [compatibility mode]
Lec 5 13_aug [compatibility mode]Palak Sanghani
 
Programimport java.util.Scanner; public class AreaOfRectangle {.pdf
Programimport java.util.Scanner; public class AreaOfRectangle {.pdfProgramimport java.util.Scanner; public class AreaOfRectangle {.pdf
Programimport java.util.Scanner; public class AreaOfRectangle {.pdfhimanshukausik409
 

Similar to Handling inputs via scanner class (20)

Computer programming 2 chapter 1-lesson 2
Computer programming 2  chapter 1-lesson 2Computer programming 2  chapter 1-lesson 2
Computer programming 2 chapter 1-lesson 2
 
Java Programs
Java ProgramsJava Programs
Java Programs
 
3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf
 
Programs.pptx
Programs.pptxPrograms.pptx
Programs.pptx
 
Getting Program Input
Getting Program Input Getting Program Input
Getting Program Input
 
Prompt a user to enter a series of integers separated by spaces and .pdf
Prompt a user to enter a series of integers separated by spaces and .pdfPrompt a user to enter a series of integers separated by spaces and .pdf
Prompt a user to enter a series of integers separated by spaces and .pdf
 
Write a program, Loopy2, that uses a loop to collect an arbitrary nu.pdf
Write a program, Loopy2, that uses a loop to collect an arbitrary nu.pdfWrite a program, Loopy2, that uses a loop to collect an arbitrary nu.pdf
Write a program, Loopy2, that uses a loop to collect an arbitrary nu.pdf
 
In JAVA! Write the program that will do the following tasks- Declare.docx
In JAVA!  Write the program that will do the following tasks- Declare.docxIn JAVA!  Write the program that will do the following tasks- Declare.docx
In JAVA! Write the program that will do the following tasks- Declare.docx
 
Write a java program that reads a numbers of scores and displays its m.docx
Write a java program that reads a numbers of scores and displays its m.docxWrite a java program that reads a numbers of scores and displays its m.docx
Write a java program that reads a numbers of scores and displays its m.docx
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ Exams
 
Java programs
Java programsJava programs
Java programs
 
JAVA Question : Programming Assignment
JAVA Question : Programming AssignmentJAVA Question : Programming Assignment
JAVA Question : Programming Assignment
 
Chap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptxChap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptx
 
program for remove unnecessary space from a given input string.imp.pdf
program for remove unnecessary space from a given input string.imp.pdfprogram for remove unnecessary space from a given input string.imp.pdf
program for remove unnecessary space from a given input string.imp.pdf
 
Java programs
Java programsJava programs
Java programs
 
Java Programs Lab File
Java Programs Lab FileJava Programs Lab File
Java Programs Lab File
 
Throwing.javaimport java.util.InputMismatchException; import jav.pdf
Throwing.javaimport java.util.InputMismatchException; import jav.pdfThrowing.javaimport java.util.InputMismatchException; import jav.pdf
Throwing.javaimport java.util.InputMismatchException; import jav.pdf
 
Lec 5 13_aug [compatibility mode]
Lec 5 13_aug [compatibility mode]Lec 5 13_aug [compatibility mode]
Lec 5 13_aug [compatibility mode]
 
Java 5 and 6 New Features
Java 5 and 6 New FeaturesJava 5 and 6 New Features
Java 5 and 6 New Features
 
Programimport java.util.Scanner; public class AreaOfRectangle {.pdf
Programimport java.util.Scanner; public class AreaOfRectangle {.pdfProgramimport java.util.Scanner; public class AreaOfRectangle {.pdf
Programimport java.util.Scanner; public class AreaOfRectangle {.pdf
 

More from simarsimmygrewal (7)

C file
C fileC file
C file
 
Java file
Java fileJava file
Java file
 
C file
C fileC file
C file
 
Handling inputs via io..continue
Handling inputs via io..continueHandling inputs via io..continue
Handling inputs via io..continue
 
Excception handling
Excception handlingExcception handling
Excception handling
 
Type casting
Type castingType casting
Type casting
 
Wrapper classes
Wrapper classesWrapper classes
Wrapper classes
 

Recently uploaded

In - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxIn - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxAditiChauhan701637
 
Education and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxEducation and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxraviapr7
 
How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17Celine George
 
The basics of sentences session 10pptx.pptx
The basics of sentences session 10pptx.pptxThe basics of sentences session 10pptx.pptx
The basics of sentences session 10pptx.pptxheathfieldcps1
 
HED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfHED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfMohonDas
 
CapTechU Doctoral Presentation -March 2024 slides.pptx
CapTechU Doctoral Presentation -March 2024 slides.pptxCapTechU Doctoral Presentation -March 2024 slides.pptx
CapTechU Doctoral Presentation -March 2024 slides.pptxCapitolTechU
 
How to Send Emails From Odoo 17 Using Code
How to Send Emails From Odoo 17 Using CodeHow to Send Emails From Odoo 17 Using Code
How to Send Emails From Odoo 17 Using CodeCeline George
 
Easter in the USA presentation by Chloe.
Easter in the USA presentation by Chloe.Easter in the USA presentation by Chloe.
Easter in the USA presentation by Chloe.EnglishCEIPdeSigeiro
 
5 charts on South Africa as a source country for international student recrui...
5 charts on South Africa as a source country for international student recrui...5 charts on South Africa as a source country for international student recrui...
5 charts on South Africa as a source country for international student recrui...CaraSkikne1
 
Vani Magazine - Quarterly Magazine of Seshadripuram Educational Trust
Vani Magazine - Quarterly Magazine of Seshadripuram Educational TrustVani Magazine - Quarterly Magazine of Seshadripuram Educational Trust
Vani Magazine - Quarterly Magazine of Seshadripuram Educational TrustSavipriya Raghavendra
 
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxAUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxiammrhaywood
 
10 Topics For MBA Project Report [HR].pdf
10 Topics For MBA Project Report [HR].pdf10 Topics For MBA Project Report [HR].pdf
10 Topics For MBA Project Report [HR].pdfJayanti Pande
 
Over the counter (OTC)- Sale, rational use.pptx
Over the counter (OTC)- Sale, rational use.pptxOver the counter (OTC)- Sale, rational use.pptx
Over the counter (OTC)- Sale, rational use.pptxraviapr7
 
Prescribed medication order and communication skills.pptx
Prescribed medication order and communication skills.pptxPrescribed medication order and communication skills.pptx
Prescribed medication order and communication skills.pptxraviapr7
 
3.21.24 The Origins of Black Power.pptx
3.21.24  The Origins of Black Power.pptx3.21.24  The Origins of Black Power.pptx
3.21.24 The Origins of Black Power.pptxmary850239
 
EBUS5423 Data Analytics and Reporting Bl
EBUS5423 Data Analytics and Reporting BlEBUS5423 Data Analytics and Reporting Bl
EBUS5423 Data Analytics and Reporting BlDr. Bruce A. Johnson
 
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRADUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRATanmoy Mishra
 
ARTICULAR DISC OF TEMPOROMANDIBULAR JOINT
ARTICULAR DISC OF TEMPOROMANDIBULAR JOINTARTICULAR DISC OF TEMPOROMANDIBULAR JOINT
ARTICULAR DISC OF TEMPOROMANDIBULAR JOINTDR. SNEHA NAIR
 

Recently uploaded (20)

In - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxIn - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptx
 
Education and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxEducation and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptx
 
Finals of Kant get Marx 2.0 : a general politics quiz
Finals of Kant get Marx 2.0 : a general politics quizFinals of Kant get Marx 2.0 : a general politics quiz
Finals of Kant get Marx 2.0 : a general politics quiz
 
How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17
 
The basics of sentences session 10pptx.pptx
The basics of sentences session 10pptx.pptxThe basics of sentences session 10pptx.pptx
The basics of sentences session 10pptx.pptx
 
HED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfHED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdf
 
CapTechU Doctoral Presentation -March 2024 slides.pptx
CapTechU Doctoral Presentation -March 2024 slides.pptxCapTechU Doctoral Presentation -March 2024 slides.pptx
CapTechU Doctoral Presentation -March 2024 slides.pptx
 
How to Send Emails From Odoo 17 Using Code
How to Send Emails From Odoo 17 Using CodeHow to Send Emails From Odoo 17 Using Code
How to Send Emails From Odoo 17 Using Code
 
Easter in the USA presentation by Chloe.
Easter in the USA presentation by Chloe.Easter in the USA presentation by Chloe.
Easter in the USA presentation by Chloe.
 
5 charts on South Africa as a source country for international student recrui...
5 charts on South Africa as a source country for international student recrui...5 charts on South Africa as a source country for international student recrui...
5 charts on South Africa as a source country for international student recrui...
 
Vani Magazine - Quarterly Magazine of Seshadripuram Educational Trust
Vani Magazine - Quarterly Magazine of Seshadripuram Educational TrustVani Magazine - Quarterly Magazine of Seshadripuram Educational Trust
Vani Magazine - Quarterly Magazine of Seshadripuram Educational Trust
 
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxAUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
 
10 Topics For MBA Project Report [HR].pdf
10 Topics For MBA Project Report [HR].pdf10 Topics For MBA Project Report [HR].pdf
10 Topics For MBA Project Report [HR].pdf
 
Over the counter (OTC)- Sale, rational use.pptx
Over the counter (OTC)- Sale, rational use.pptxOver the counter (OTC)- Sale, rational use.pptx
Over the counter (OTC)- Sale, rational use.pptx
 
Prescribed medication order and communication skills.pptx
Prescribed medication order and communication skills.pptxPrescribed medication order and communication skills.pptx
Prescribed medication order and communication skills.pptx
 
3.21.24 The Origins of Black Power.pptx
3.21.24  The Origins of Black Power.pptx3.21.24  The Origins of Black Power.pptx
3.21.24 The Origins of Black Power.pptx
 
Prelims of Kant get Marx 2.0: a general politics quiz
Prelims of Kant get Marx 2.0: a general politics quizPrelims of Kant get Marx 2.0: a general politics quiz
Prelims of Kant get Marx 2.0: a general politics quiz
 
EBUS5423 Data Analytics and Reporting Bl
EBUS5423 Data Analytics and Reporting BlEBUS5423 Data Analytics and Reporting Bl
EBUS5423 Data Analytics and Reporting Bl
 
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRADUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
 
ARTICULAR DISC OF TEMPOROMANDIBULAR JOINT
ARTICULAR DISC OF TEMPOROMANDIBULAR JOINTARTICULAR DISC OF TEMPOROMANDIBULAR JOINT
ARTICULAR DISC OF TEMPOROMANDIBULAR JOINT
 

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); } }