SlideShare a Scribd company logo
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.
Lesson 5 - Getting Input from Users.pdf
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
Lesson 5 - Getting Input from Users.pdf
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 (7)

PPTX
Introduction to java
Java Lover
 
PPT
Springboot introduction
Sagar Verma
 
PDF
Automação - Sistema de controle
Ciro Marcus
 
PPTX
Java programming course for beginners
Eduonix Learning Solutions
 
PDF
Java Training | Java Tutorial for Beginners | Java Programming | Java Certifi...
Edureka!
 
PDF
8a Curso de POO en Java - crear proyecto eclipse
Clara Patricia Avella Ibañez
 
PDF
Object oriented concepts
Pranali Chaudhari
 
Introduction to java
Java Lover
 
Springboot introduction
Sagar Verma
 
Automação - Sistema de controle
Ciro Marcus
 
Java programming course for beginners
Eduonix Learning Solutions
 
Java Training | Java Tutorial for Beginners | Java Programming | Java Certifi...
Edureka!
 
8a Curso de POO en Java - crear proyecto eclipse
Clara Patricia Avella Ibañez
 
Object oriented concepts
Pranali Chaudhari
 

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

PPTX
Chapter 3.4
sotlsoc
 
PPT
9781111530532 ppt ch02
Terry Yoast
 
PPT
presentation of java fundamental
Ganesh Chittalwar
 
PPT
Chapter 2 - Basic Elements of Java
Adan Hubahib
 
DOC
Lewis jssap3 e_labman02
auswhit
 
PDF
Lec-2- Ehsjdjkck. Jdkdbd djskrogramming.pdf
RahulKumar342376
 
PDF
djkkfhulkgyftfdtrdrsdsjjjjjjjjjjjjjjjjjjj
AbhishekSingh757567
 
PDF
3.Lesson Plan - Input.pdf.pdf
AbhishekSingh757567
 
PPT
9781111530532 ppt ch02
Terry Yoast
 
PPT
Chapter2pp
J. C.
 
PPT
Chapter 2- Prog101.ppt
JosephObadiahTuray
 
PPTX
OOP Using Java Ch2 all about oop .pptx
doopagamer
 
PPT
Comp102 lec 4
Fraz Bakhsh
 
PPTX
Lecture-5Programming WorldJava Lecture.pptx
talhazc013
 
PPTX
VARIABLE AND DATATYPES-JAVA.pptx
Marisol Domingo
 
PPT
Basic elements of java
Ahmad Idrees
 
PPT
02slidLarge value of face area Large value of face area
AhmadHashlamon
 
PPTX
Java basics variables
JoeReddieMedia
 
PPT
ch06-file-processing.ppt
Mahyuddin8
 
Chapter 3.4
sotlsoc
 
9781111530532 ppt ch02
Terry Yoast
 
presentation of java fundamental
Ganesh Chittalwar
 
Chapter 2 - Basic Elements of Java
Adan Hubahib
 
Lewis jssap3 e_labman02
auswhit
 
Lec-2- Ehsjdjkck. Jdkdbd djskrogramming.pdf
RahulKumar342376
 
djkkfhulkgyftfdtrdrsdsjjjjjjjjjjjjjjjjjjj
AbhishekSingh757567
 
3.Lesson Plan - Input.pdf.pdf
AbhishekSingh757567
 
9781111530532 ppt ch02
Terry Yoast
 
Chapter2pp
J. C.
 
Chapter 2- Prog101.ppt
JosephObadiahTuray
 
OOP Using Java Ch2 all about oop .pptx
doopagamer
 
Comp102 lec 4
Fraz Bakhsh
 
Lecture-5Programming WorldJava Lecture.pptx
talhazc013
 
VARIABLE AND DATATYPES-JAVA.pptx
Marisol Domingo
 
Basic elements of java
Ahmad Idrees
 
02slidLarge value of face area Large value of face area
AhmadHashlamon
 
Java basics variables
JoeReddieMedia
 
ch06-file-processing.ppt
Mahyuddin8
 
Ad

More from ROWELL MARQUINA (20)

PDF
WSAT Lesson 3 - Introduction to HTML.pdf
ROWELL MARQUINA
 
PDF
PLD Lesson 5 - Displaying Text and Comment on the Screen.pdf
ROWELL MARQUINA
 
PDF
COM Lesson 1 - Introduction to Computer Organization and Management.pdf
ROWELL MARQUINA
 
PDF
PROG3 Lesson 4 - Setting Up the VS Code Environment.pdf
ROWELL MARQUINA
 
PDF
PLD Lesson 4 - Setting Up the VS Code Environment.pdf
ROWELL MARQUINA
 
PDF
PLD Lesson 3 - Flowcharting Conditional Statements.pdf
ROWELL MARQUINA
 
PDF
FoR Lesson 1 - Introduction to Research.pdf
ROWELL MARQUINA
 
PDF
Lesson 3 - Understanding Professional Ethics.pdf
ROWELL MARQUINA
 
PDF
WSAT Lesson 2 - Introduction to World Wide Web.pdf
ROWELL MARQUINA
 
PDF
WSAT Lesson 1 - Introduction to Web Systems and Technologies.pdf
ROWELL MARQUINA
 
PDF
ITSP Lesson 2 - Ethical Principles and Theories.pdf
ROWELL MARQUINA
 
PDF
ITSP Lesson 1 - Ethics and Its History.pdf
ROWELL MARQUINA
 
PDF
WSAT Lesson 1 - Introduction to Web Systems and Technologies.pdf
ROWELL MARQUINA
 
PDF
Lesson 2 - Algorithm and Flowcharting.pdf
ROWELL MARQUINA
 
PDF
Introduction to Programming and Languages.pdf
ROWELL MARQUINA
 
PDF
QMMS Lesson 2 - Using MS Excel Formula.pdf
ROWELL MARQUINA
 
PPTX
QMMS Lesson 2 - Using Excel Formula.pptx
ROWELL MARQUINA
 
PDF
HCI Lesson 2 - Components of Human-Computer Interaction (HCI).pdf
ROWELL MARQUINA
 
PDF
HCI Lesson 1 - Introduction to Human-Computer Interaction.pdf
ROWELL MARQUINA
 
PDF
DS Lesson 2 - Subsets, Supersets and Power Set.pdf
ROWELL MARQUINA
 
WSAT Lesson 3 - Introduction to HTML.pdf
ROWELL MARQUINA
 
PLD Lesson 5 - Displaying Text and Comment on the Screen.pdf
ROWELL MARQUINA
 
COM Lesson 1 - Introduction to Computer Organization and Management.pdf
ROWELL MARQUINA
 
PROG3 Lesson 4 - Setting Up the VS Code Environment.pdf
ROWELL MARQUINA
 
PLD Lesson 4 - Setting Up the VS Code Environment.pdf
ROWELL MARQUINA
 
PLD Lesson 3 - Flowcharting Conditional Statements.pdf
ROWELL MARQUINA
 
FoR Lesson 1 - Introduction to Research.pdf
ROWELL MARQUINA
 
Lesson 3 - Understanding Professional Ethics.pdf
ROWELL MARQUINA
 
WSAT Lesson 2 - Introduction to World Wide Web.pdf
ROWELL MARQUINA
 
WSAT Lesson 1 - Introduction to Web Systems and Technologies.pdf
ROWELL MARQUINA
 
ITSP Lesson 2 - Ethical Principles and Theories.pdf
ROWELL MARQUINA
 
ITSP Lesson 1 - Ethics and Its History.pdf
ROWELL MARQUINA
 
WSAT Lesson 1 - Introduction to Web Systems and Technologies.pdf
ROWELL MARQUINA
 
Lesson 2 - Algorithm and Flowcharting.pdf
ROWELL MARQUINA
 
Introduction to Programming and Languages.pdf
ROWELL MARQUINA
 
QMMS Lesson 2 - Using MS Excel Formula.pdf
ROWELL MARQUINA
 
QMMS Lesson 2 - Using Excel Formula.pptx
ROWELL MARQUINA
 
HCI Lesson 2 - Components of Human-Computer Interaction (HCI).pdf
ROWELL MARQUINA
 
HCI Lesson 1 - Introduction to Human-Computer Interaction.pdf
ROWELL MARQUINA
 
DS Lesson 2 - Subsets, Supersets and Power Set.pdf
ROWELL MARQUINA
 
Ad

Recently uploaded (20)

PDF
Federal dollars withheld by district, charter, grant recipient
Mebane Rash
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PPTX
Latest Features in Odoo 18 - Odoo slides
Celine George
 
PPTX
Views on Education of Indian Thinkers J.Krishnamurthy..pptx
ShrutiMahanta1
 
PPTX
Accounting Skills Paper-I, Preparation of Vouchers
Dr. Sushil Bansode
 
PPTX
Pyhton with Mysql to perform CRUD operations.pptx
Ramakrishna Reddy Bijjam
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PDF
IMP NAAC-Reforms-Stakeholder-Consultation-Presentation-on-Draft-Metrics-Unive...
BHARTIWADEKAR
 
PPTX
PPT on the Development of Education in the Victorian England
Beena E S
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PPTX
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PPTX
Gall bladder, Small intestine and Large intestine.pptx
rekhapositivity
 
PPTX
How to Configure Access Rights of Manufacturing Orders in Odoo 18 Manufacturing
Celine George
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
PPTX
CONVULSIVE DISORDERS: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
PDF
BÀI TẬP BỔ TRỢ THEO LESSON TIẾNG ANH - I-LEARN SMART WORLD 7 - CẢ NĂM - CÓ ĐÁ...
Nguyen Thanh Tu Collection
 
PPTX
HEAD INJURY IN CHILDREN: NURSING MANAGEMENGT.pptx
PRADEEP ABOTHU
 
PPTX
How to Configure Storno Accounting in Odoo 18 Accounting
Celine George
 
PPTX
How to Configure Lost Reasons in Odoo 18 CRM
Celine George
 
PPSX
Health Planning in india - Unit 03 - CHN 2 - GNM 3RD YEAR.ppsx
Priyanshu Anand
 
Federal dollars withheld by district, charter, grant recipient
Mebane Rash
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
Latest Features in Odoo 18 - Odoo slides
Celine George
 
Views on Education of Indian Thinkers J.Krishnamurthy..pptx
ShrutiMahanta1
 
Accounting Skills Paper-I, Preparation of Vouchers
Dr. Sushil Bansode
 
Pyhton with Mysql to perform CRUD operations.pptx
Ramakrishna Reddy Bijjam
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
IMP NAAC-Reforms-Stakeholder-Consultation-Presentation-on-Draft-Metrics-Unive...
BHARTIWADEKAR
 
PPT on the Development of Education in the Victorian England
Beena E S
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
Gall bladder, Small intestine and Large intestine.pptx
rekhapositivity
 
How to Configure Access Rights of Manufacturing Orders in Odoo 18 Manufacturing
Celine George
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
CONVULSIVE DISORDERS: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
BÀI TẬP BỔ TRỢ THEO LESSON TIẾNG ANH - I-LEARN SMART WORLD 7 - CẢ NĂM - CÓ ĐÁ...
Nguyen Thanh Tu Collection
 
HEAD INJURY IN CHILDREN: NURSING MANAGEMENGT.pptx
PRADEEP ABOTHU
 
How to Configure Storno Accounting in Odoo 18 Accounting
Celine George
 
How to Configure Lost Reasons in Odoo 18 CRM
Celine George
 
Health Planning in india - Unit 03 - CHN 2 - GNM 3RD YEAR.ppsx
Priyanshu Anand
 

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.
  • 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
  • 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: [email protected] [email protected] [email protected]