SlideShare a Scribd company logo
1 of 25
Download to read offline
TUNASAN NATIONAL HIGH SCHOOL
SDO - Muntinlupa City
ROWELL L. MARQUINA
Senior High School Teacher
TUNASAN NATIONAL HIGH SCHOOL
Lesson 5 - Java Programming
LEARNING OBJECTIVES:
At the end of the session, you will be able to:
1. discuss what is a Scanner class;
2. know how to import and make use
of the Scanner class;
3. select the appropriate input
methods in accommodating
user’s input/s; and
4. create a program that will require
input/s from the user.
The Scanner class is a method in Java that is used to
capture data that is entered by the user. It is included in the
java.util package.
If the programmer intends to create a program that will
accept inputs from the user, the scanner class must be
imported at the very beginning of the code.
JAVA SCANNER CLASS
After successfully importing a Scanner class the next thing,
we must create is a Scanner object. The Scanner object is a
representation of the scanner that is necessary when
invoking the scanner for use.
Create the scanner object at beginning of the program
body to avoid conflicts when invoking the scanner at
the later parts of the program.
JAVA SCANNER CLASS
EXAMPLE 1:
Create a program that will
require the user to input their
first name. The program will
then display a greeting with
the name of the user.
IMPORTING THE SCANNER
As discussed earlier, to use the Scanner class we must
first import it by invoking the Java statement:
DECLARING A VARIABLE
We will declare a string variable called “name” . The
“name” is the variable that will represent the data
entered by the user.
CREATING A SCANNER OBJECT
In this example, we initiated a scanner called “mitis”.
The scanner “mitis” is being introduced here as a new
scanner and as method of getting input from the user.
DISPLAYING TEXT ON SCREEN
We displayed the question “What is your name?” using
the print method to display the instruction for our user.
ASSIGNING DATA TO A VARIABLE
Since the program is already familiar with the variable
called “name”, we can now use it to represent any
value that our scanner captured in the process.
ASSIGNING DATA TO A VARIABLE
This statement instructs the program that the input will
be captured using the scanner named “ mitis”. The
“nextLine( )” statement tells the program that the
incoming input is a String.
DISPLAYING TEXT ON SCREEN
This statement instructs the program to display the
greeting “Good morning” followed by whatever value
contained in the variable name. The greeting will end
with “!”.
SOURCE CODE AND OUTPUTS
SOURCE CODE: SAMPLE OUTPUTS:
EXAMPLE 2:
COMPUTING FOR AGE:
Create a program that will
require the user to input their
birth year. The program will
compute for the user’s age
using the inputted birth year
and display it on the screen.
SOURCE CODE:
EXAMPLE 3:
SUM OF TWO NUMBERS:
Create a program that will
require the user to input two
numbers. The program will
compute for the sum of the
numbers inputted by the user
and display it on the screen.
SOURCE CODE:
EXAMPLE 4:
KILOGRAM TO POUND
CONVERSION:
Create a program that will require
the user to input a value in
kilogram. The program will convert
the value inputted by the user to
pound by using the conversion
1 kg = 2.2 lbs.
SOURCE CODE:
PRACTICE TEST 1:
COMPUTING FOR AREA:
Create a flowchart for a program that will
require the user to input the length and width of
a rectangle. The program will compute for the
area of the rectangle using the inputted length
and with and display its results on the screen.
PRACTICE TEST 2:
COMPUTING FOR AVERAGE
Create a flowchart for a program that will
require the user to input their grades in
Mathematics, English, and Science. The
program will compute for the average of the
three grades and display its result on the
computer screen.
PRACTICE TEST 3:
PLAYING WITH NUMBERS:
Create a flowchart for a program that will
require the user to input four numbers. Using
the inputs, the program will compute for:
▪ the sum of 1st and 2nd number,
▪ the product of the 3rd and 4th number
▪ the square of the 2nd number
GETTING INPUTS FROM USERS
MR. ROWELL L. MARQUINA
Tunasan National High School
Senior High School Department
Email Address:
rowell.marquina001@deped.gov.ph
sirrowellmarquina@gmail.com
rmarquina@mitis.edu.ph

More Related Content

What's hot

Praktikum 11 http web server dan mail server pada cisco pt (domain)
Praktikum 11 http web server  dan mail server pada cisco pt (domain)Praktikum 11 http web server  dan mail server pada cisco pt (domain)
Praktikum 11 http web server dan mail server pada cisco pt (domain)
Samsugi S
 

What's hot (20)

Praktikum 11 http web server dan mail server pada cisco pt (domain)
Praktikum 11 http web server  dan mail server pada cisco pt (domain)Praktikum 11 http web server  dan mail server pada cisco pt (domain)
Praktikum 11 http web server dan mail server pada cisco pt (domain)
 
tugas microsoft power point
tugas microsoft power pointtugas microsoft power point
tugas microsoft power point
 
Header files in c
Header files in cHeader files in c
Header files in c
 
Laporan ftp
Laporan ftpLaporan ftp
Laporan ftp
 
Software Process Models
Software Process ModelsSoftware Process Models
Software Process Models
 
Slicing and testing
Slicing and testingSlicing and testing
Slicing and testing
 
Mengenal Camtasia Studio
Mengenal Camtasia StudioMengenal Camtasia Studio
Mengenal Camtasia Studio
 
Modul Mikrokontroler - Bab 3. Pemrograman Mikrokontroler
Modul Mikrokontroler - Bab 3. Pemrograman MikrokontrolerModul Mikrokontroler - Bab 3. Pemrograman Mikrokontroler
Modul Mikrokontroler - Bab 3. Pemrograman Mikrokontroler
 
Function in c language(defination and declaration)
Function in c language(defination and declaration)Function in c language(defination and declaration)
Function in c language(defination and declaration)
 
Konsep oop pada php dan mvc pada php framework, 1200631047 1200631018 1200631028
Konsep oop pada php dan mvc pada php framework, 1200631047 1200631018 1200631028Konsep oop pada php dan mvc pada php framework, 1200631047 1200631018 1200631028
Konsep oop pada php dan mvc pada php framework, 1200631047 1200631018 1200631028
 
Komunikasi data dan suara
Komunikasi data dan suaraKomunikasi data dan suara
Komunikasi data dan suara
 
Modul belajar java I/O (Input/Ouptut)
Modul belajar java I/O (Input/Ouptut)Modul belajar java I/O (Input/Ouptut)
Modul belajar java I/O (Input/Ouptut)
 
Simple Java Programs
Simple Java ProgramsSimple Java Programs
Simple Java Programs
 
Input output streams
Input output streamsInput output streams
Input output streams
 
Basic Java Programming
Basic Java ProgrammingBasic Java Programming
Basic Java Programming
 
Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2
 
Call by value or call by reference in C++
Call by value or call by reference in C++Call by value or call by reference in C++
Call by value or call by reference in C++
 
Java features
Java featuresJava features
Java features
 
Pemrograman terstruktur
Pemrograman terstrukturPemrograman terstruktur
Pemrograman terstruktur
 
Empowerment Technology Lesson 3
Empowerment Technology Lesson 3Empowerment Technology Lesson 3
Empowerment Technology Lesson 3
 

Similar to Lesson 5 - Getting Input from Users.pdf

66781291 java-lab-manual
66781291 java-lab-manual66781291 java-lab-manual
66781291 java-lab-manual
Laura Popovici
 
Lesson 1 - Algorithm and Flowcharting.pdf
Lesson 1 - Algorithm and Flowcharting.pdfLesson 1 - Algorithm and Flowcharting.pdf
Lesson 1 - Algorithm and Flowcharting.pdf
ROWELL MARQUINA
 
Cis 247 all i labs
Cis 247 all i labsCis 247 all i labs
Cis 247 all i labs
ccis224477
 
Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6
helpido9
 
Cis 355 ilab 1 of 6
Cis 355 ilab 1 of 6Cis 355 ilab 1 of 6
Cis 355 ilab 1 of 6
comp274
 
Cis247 i lab 1 of 7 creating a user interface
Cis247 i lab 1 of 7 creating a user interfaceCis247 i lab 1 of 7 creating a user interface
Cis247 i lab 1 of 7 creating a user interface
sdjdskjd9097
 
Cis247 a ilab 1 of 7 creating a user interface
Cis247 a ilab 1 of 7 creating a user interfaceCis247 a ilab 1 of 7 creating a user interface
Cis247 a ilab 1 of 7 creating a user interface
ccis224477
 
Cis355 a ilab 2 control structures and user defined methods devry university
Cis355 a ilab 2 control structures and user defined methods devry universityCis355 a ilab 2 control structures and user defined methods devry university
Cis355 a ilab 2 control structures and user defined methods devry university
sjskjd709707
 
Android development training programme , Day 3
Android development training programme , Day 3Android development training programme , Day 3
Android development training programme , Day 3
DHIRAJ PRAVIN
 

Similar to Lesson 5 - Getting Input from Users.pdf (20)

66781291 java-lab-manual
66781291 java-lab-manual66781291 java-lab-manual
66781291 java-lab-manual
 
DSA Lesson 2 - Algorithm and Flowcharting.pdf
DSA Lesson 2 - Algorithm and Flowcharting.pdfDSA Lesson 2 - Algorithm and Flowcharting.pdf
DSA Lesson 2 - Algorithm and Flowcharting.pdf
 
Lesson 1 - Algorithm and Flowcharting.pdf
Lesson 1 - Algorithm and Flowcharting.pdfLesson 1 - Algorithm and Flowcharting.pdf
Lesson 1 - Algorithm and Flowcharting.pdf
 
OOP Programs
OOP ProgramsOOP Programs
OOP Programs
 
Java lab-manual
Java lab-manualJava lab-manual
Java lab-manual
 
Cis 247 all i labs
Cis 247 all i labsCis 247 all i labs
Cis 247 all i labs
 
Intro to programing with java-lecture 1
Intro to programing with java-lecture 1Intro to programing with java-lecture 1
Intro to programing with java-lecture 1
 
Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6
 
Cis 355 ilab 1 of 6
Cis 355 ilab 1 of 6Cis 355 ilab 1 of 6
Cis 355 ilab 1 of 6
 
Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6
 
Chapter 2- Prog101.ppt
Chapter 2- Prog101.pptChapter 2- Prog101.ppt
Chapter 2- Prog101.ppt
 
Cis247 i lab 1 of 7 creating a user interface
Cis247 i lab 1 of 7 creating a user interfaceCis247 i lab 1 of 7 creating a user interface
Cis247 i lab 1 of 7 creating a user interface
 
Cis247 a ilab 1 of 7 creating a user interface
Cis247 a ilab 1 of 7 creating a user interfaceCis247 a ilab 1 of 7 creating a user interface
Cis247 a ilab 1 of 7 creating a user interface
 
Cis355 a ilab 2 control structures and user defined methods devry university
Cis355 a ilab 2 control structures and user defined methods devry universityCis355 a ilab 2 control structures and user defined methods devry university
Cis355 a ilab 2 control structures and user defined methods devry university
 
Solutions manual for absolute java 5th edition by walter savitch
Solutions manual for absolute java 5th edition by walter savitchSolutions manual for absolute java 5th edition by walter savitch
Solutions manual for absolute java 5th edition by walter savitch
 
AndroidHTP3_AppA.pptx
AndroidHTP3_AppA.pptxAndroidHTP3_AppA.pptx
AndroidHTP3_AppA.pptx
 
C++ Lab Maual.pdf
C++ Lab Maual.pdfC++ Lab Maual.pdf
C++ Lab Maual.pdf
 
C++ Lab Maual.pdf
C++ Lab Maual.pdfC++ Lab Maual.pdf
C++ Lab Maual.pdf
 
Compiling and understanding first program in java
Compiling and understanding first program in javaCompiling and understanding first program in java
Compiling and understanding first program in java
 
Android development training programme , Day 3
Android development training programme , Day 3Android development training programme , Day 3
Android development training programme , Day 3
 

More from ROWELL MARQUINA

QMMS Lesson 2 - Using Excel Formula.pptx
QMMS Lesson 2 - Using Excel Formula.pptxQMMS Lesson 2 - Using Excel Formula.pptx
QMMS Lesson 2 - Using Excel Formula.pptx
ROWELL MARQUINA
 
HCI Lesson 2 - Components of Human-Computer Interaction (HCI).pdf
HCI Lesson 2 - Components of Human-Computer Interaction (HCI).pdfHCI Lesson 2 - Components of Human-Computer Interaction (HCI).pdf
HCI Lesson 2 - Components of Human-Computer Interaction (HCI).pdf
ROWELL MARQUINA
 
ITSP Lesson 1 - Ethics and Ethical Theories.pdf
ITSP Lesson 1 - Ethics and Ethical Theories.pdfITSP Lesson 1 - Ethics and Ethical Theories.pdf
ITSP Lesson 1 - Ethics and Ethical Theories.pdf
ROWELL MARQUINA
 

More from ROWELL MARQUINA (19)

QMMS Lesson 2 - Using MS Excel Formula.pdf
QMMS Lesson 2 - Using MS Excel Formula.pdfQMMS Lesson 2 - Using MS Excel Formula.pdf
QMMS Lesson 2 - Using MS Excel Formula.pdf
 
QMMS Lesson 2 - Using Excel Formula.pptx
QMMS Lesson 2 - Using Excel Formula.pptxQMMS Lesson 2 - Using Excel Formula.pptx
QMMS Lesson 2 - Using Excel Formula.pptx
 
HCI Lesson 2 - Components of Human-Computer Interaction (HCI).pdf
HCI Lesson 2 - Components of Human-Computer Interaction (HCI).pdfHCI Lesson 2 - Components of Human-Computer Interaction (HCI).pdf
HCI Lesson 2 - Components of Human-Computer Interaction (HCI).pdf
 
HCI Lesson 1 - Introduction to Human-Computer Interaction.pdf
HCI Lesson 1 - Introduction to Human-Computer Interaction.pdfHCI Lesson 1 - Introduction to Human-Computer Interaction.pdf
HCI Lesson 1 - Introduction to Human-Computer Interaction.pdf
 
DS Lesson 2 - Subsets, Supersets and Power Set.pdf
DS Lesson 2 - Subsets, Supersets and Power Set.pdfDS Lesson 2 - Subsets, Supersets and Power Set.pdf
DS Lesson 2 - Subsets, Supersets and Power Set.pdf
 
ITSP Lesson 6 - Information Privacy.pdf
ITSP Lesson 6 - Information Privacy.pdfITSP Lesson 6 - Information Privacy.pdf
ITSP Lesson 6 - Information Privacy.pdf
 
ITSP Lesson 5 - Intellectual Property Rights.pdf
ITSP Lesson 5 - Intellectual Property Rights.pdfITSP Lesson 5 - Intellectual Property Rights.pdf
ITSP Lesson 5 - Intellectual Property Rights.pdf
 
ITSP Lesson 1 - Ethics and Ethical Theories.pdf
ITSP Lesson 1 - Ethics and Ethical Theories.pdfITSP Lesson 1 - Ethics and Ethical Theories.pdf
ITSP Lesson 1 - Ethics and Ethical Theories.pdf
 
ITSP Lesson 1 - Ethics and Ethical Theories.pdf
ITSP Lesson 1 - Ethics and Ethical Theories.pdfITSP Lesson 1 - Ethics and Ethical Theories.pdf
ITSP Lesson 1 - Ethics and Ethical Theories.pdf
 
CHF Lesson 2 - Software and Software Categories.pdf
CHF Lesson 2 - Software and Software Categories.pdfCHF Lesson 2 - Software and Software Categories.pdf
CHF Lesson 2 - Software and Software Categories.pdf
 
Animation Lesson 4 - Tools and Equipment in Animation.pdf
Animation Lesson 4 - Tools and Equipment in Animation.pdfAnimation Lesson 4 - Tools and Equipment in Animation.pdf
Animation Lesson 4 - Tools and Equipment in Animation.pdf
 
DSA Lesson 1 - Introduction to Data Structures.pdf
DSA Lesson 1 - Introduction to Data Structures.pdfDSA Lesson 1 - Introduction to Data Structures.pdf
DSA Lesson 1 - Introduction to Data Structures.pdf
 
Lesson 1 - Introduction to Programming .pdf
Lesson 1 - Introduction to Programming .pdfLesson 1 - Introduction to Programming .pdf
Lesson 1 - Introduction to Programming .pdf
 
Animation Lesson 3 - Occupational Health and Safety Procedures.pdf
Animation Lesson 3 - Occupational Health and Safety Procedures.pdfAnimation Lesson 3 - Occupational Health and Safety Procedures.pdf
Animation Lesson 3 - Occupational Health and Safety Procedures.pdf
 
Animation Lesson 2 - Environment and Market (Updated).pdf
Animation Lesson 2 - Environment and Market (Updated).pdfAnimation Lesson 2 - Environment and Market (Updated).pdf
Animation Lesson 2 - Environment and Market (Updated).pdf
 
Animation Lesson 3 - Occupational Health and Safety Procedures.pdf
Animation Lesson 3 - Occupational Health and Safety Procedures.pdfAnimation Lesson 3 - Occupational Health and Safety Procedures.pdf
Animation Lesson 3 - Occupational Health and Safety Procedures.pdf
 
Personal Entrepreneurial Competencies (PECs).pdf
Personal Entrepreneurial Competencies (PECs).pdfPersonal Entrepreneurial Competencies (PECs).pdf
Personal Entrepreneurial Competencies (PECs).pdf
 
Environment and Market.pdf
Environment and Market.pdfEnvironment and Market.pdf
Environment and Market.pdf
 
Lesson 3 - Displaying Text on Screen.pdf
Lesson 3 - Displaying Text on Screen.pdfLesson 3 - Displaying Text on Screen.pdf
Lesson 3 - Displaying Text on Screen.pdf
 

Recently uploaded

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 

Lesson 5 - Getting Input from Users.pdf

  • 1. TUNASAN NATIONAL HIGH SCHOOL SDO - Muntinlupa City ROWELL L. MARQUINA Senior High School Teacher TUNASAN NATIONAL HIGH SCHOOL Lesson 5 - Java Programming
  • 2. LEARNING OBJECTIVES: At the end of the session, you will be able to: 1. discuss what is a Scanner class; 2. know how to import and make use of the Scanner class; 3. select the appropriate input methods in accommodating user’s input/s; and 4. create a program that will require input/s from the user.
  • 3.
  • 4. The Scanner class is a method in Java that is used to capture data that is entered by the user. It is included in the java.util package. If the programmer intends to create a program that will accept inputs from the user, the scanner class must be imported at the very beginning of the code. JAVA SCANNER CLASS
  • 5. After successfully importing a Scanner class the next thing, we must create is a Scanner object. The Scanner object is a representation of the scanner that is necessary when invoking the scanner for use. Create the scanner object at beginning of the program body to avoid conflicts when invoking the scanner at the later parts of the program. JAVA SCANNER CLASS
  • 6.
  • 7. EXAMPLE 1: Create a program that will require the user to input their first name. The program will then display a greeting with the name of the user.
  • 8. IMPORTING THE SCANNER As discussed earlier, to use the Scanner class we must first import it by invoking the Java statement:
  • 9. DECLARING A VARIABLE We will declare a string variable called “name” . The “name” is the variable that will represent the data entered by the user.
  • 10. CREATING A SCANNER OBJECT In this example, we initiated a scanner called “mitis”. The scanner “mitis” is being introduced here as a new scanner and as method of getting input from the user.
  • 11. DISPLAYING TEXT ON SCREEN We displayed the question “What is your name?” using the print method to display the instruction for our user.
  • 12. ASSIGNING DATA TO A VARIABLE Since the program is already familiar with the variable called “name”, we can now use it to represent any value that our scanner captured in the process.
  • 13. ASSIGNING DATA TO A VARIABLE This statement instructs the program that the input will be captured using the scanner named “ mitis”. The “nextLine( )” statement tells the program that the incoming input is a String.
  • 14. DISPLAYING TEXT ON SCREEN This statement instructs the program to display the greeting “Good morning” followed by whatever value contained in the variable name. The greeting will end with “!”.
  • 15. SOURCE CODE AND OUTPUTS SOURCE CODE: SAMPLE OUTPUTS:
  • 16. EXAMPLE 2: COMPUTING FOR AGE: Create a program that will require the user to input their birth year. The program will compute for the user’s age using the inputted birth year and display it on the screen.
  • 18. EXAMPLE 3: SUM OF TWO NUMBERS: Create a program that will require the user to input two numbers. The program will compute for the sum of the numbers inputted by the user and display it on the screen.
  • 20. EXAMPLE 4: KILOGRAM TO POUND CONVERSION: Create a program that will require the user to input a value in kilogram. The program will convert the value inputted by the user to pound by using the conversion 1 kg = 2.2 lbs.
  • 22. PRACTICE TEST 1: COMPUTING FOR AREA: Create a flowchart for a program that will require the user to input the length and width of a rectangle. The program will compute for the area of the rectangle using the inputted length and with and display its results on the screen.
  • 23. PRACTICE TEST 2: COMPUTING FOR AVERAGE Create a flowchart for a program that will require the user to input their grades in Mathematics, English, and Science. The program will compute for the average of the three grades and display its result on the computer screen.
  • 24. PRACTICE TEST 3: PLAYING WITH NUMBERS: Create a flowchart for a program that will require the user to input four numbers. Using the inputs, the program will compute for: ▪ the sum of 1st and 2nd number, ▪ the product of the 3rd and 4th number ▪ the square of the 2nd number
  • 25. GETTING INPUTS FROM USERS MR. ROWELL L. MARQUINA Tunasan National High School Senior High School Department Email Address: rowell.marquina001@deped.gov.ph sirrowellmarquina@gmail.com rmarquina@mitis.edu.ph