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

Introduction to visual basic programming
Introduction to visual basic programmingIntroduction to visual basic programming
Introduction to visual basic programming
Roger Argarin
 
Java Presentation
Java PresentationJava Presentation
Java Presentation
aitrichtech
 

What's hot (20)

Seminar on java
Seminar on javaSeminar on java
Seminar on java
 
Introduction to visual basic programming
Introduction to visual basic programmingIntroduction to visual basic programming
Introduction to visual basic programming
 
interface in c#
interface in c#interface in c#
interface in c#
 
Interfaces in java
Interfaces in javaInterfaces in java
Interfaces in java
 
Introduction of java
Introduction  of javaIntroduction  of java
Introduction of java
 
Core Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsCore Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika Tutorials
 
Java
JavaJava
Java
 
Core Java
Core JavaCore Java
Core Java
 
Java Presentation
Java PresentationJava Presentation
Java Presentation
 
JRE , JDK and platform independent nature of JAVA
JRE , JDK and platform independent nature of JAVAJRE , JDK and platform independent nature of JAVA
JRE , JDK and platform independent nature of JAVA
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Applets in java
Applets in javaApplets in java
Applets in java
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
 
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...
 
Java - Packages Concepts
Java - Packages ConceptsJava - Packages Concepts
Java - Packages Concepts
 
Introduction to c#
Introduction to c#Introduction to c#
Introduction to c#
 
Applets
AppletsApplets
Applets
 
Oops concept on c#
Oops concept on c#Oops concept on c#
Oops concept on c#
 

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
 
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
 
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
cis247
 

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
 
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 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
 
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
 
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
 

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 4 - Data and Variables.pdf
Lesson 4 - Data and Variables.pdfLesson 4 - Data and Variables.pdf
Lesson 4 - Data and Variables.pdf
 

Recently uploaded

Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
EADTU
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 

Recently uploaded (20)

Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 

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