0% found this document useful (0 votes)
26 views8 pages

Lecture - 3.4-Scanner Class

The document discusses the use of the Scanner class in Java for taking user input. It explains how to create a Scanner object, the standard input and output devices, and provides commonly used methods for reading different data types. Additionally, it includes exercises for practicing input operations using the Scanner class.

Uploaded by

fahim2305101854
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)
26 views8 pages

Lecture - 3.4-Scanner Class

The document discusses the use of the Scanner class in Java for taking user input. It explains how to create a Scanner object, the standard input and output devices, and provides commonly used methods for reading different data types. Additionally, it includes exercises for practicing input operations using the Scanner class.

Uploaded by

fahim2305101854
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/ 8

Lecture – 3.

4
JAVA: Scanner Class

Afsara Tasneem Misha


Lecturer
Department of CSE
Daffodil International University
1
Today’s Topics
• Taking input using Scanner class

• Some exercises using scanner class


Taking input from User
Scanner Class

• ‘Scanner’ class is used to take input from user

• An object of Scanner class is created to read input

• Java uses System.out to refer to the standard output device and


System.in to standard input device

• Import ‘java.util.Scanner’ package to use scanner class


Commonly used methods for Scanner class

• nextByte(): reads an Byte value from the user


• nextShort() : reads an Short value from the user
• nextInt() : reads an int value from the user
• nextLong() : reads an Long Integer value from the user
• nextFloat() : reads an Float value from the user
• nextDouble() : reads an Double value from the user
• next() : reads a word from the user
• nextLine() : reads a Line of Text from the user
Exercise
Using Scanner class

• Take two integer numbers as input and calculate their sum.

• Calculate the area of a circle. Take radius as input.

• Take some information about yourself (i.e. name, age, cgpa, department,
section etc) as input and display them.
1.import java.util.*;
2.public class ScannerExample {
3.public static void main(String args[]){
4. Scanner in = new Scanner(System.in);
5. System.out.print("Enter your name: ");
6. String name = in.nextLine();
7. System.out.println("Name is: " + name);
8. }
9. }
Thank You

You might also like