You are on page 1of 33

Click to edit Master title style

Basic Java – User input


and Arithmetic Operators
Lesson Topics
Click to edit Master title style

1. Built-in Packages
2. Importing Packages
3. Java.util.Scanner;
4. User Input
5. Arithmetic Operators
6. Activity
BUILT-IN PACKAGES
Click to edit Master title style

Java API has many pre-written classes to


help the programmer manage input , database
and etc.
IMPORTING PACKAGES
Click to edit Master title style

IMPORT SPECIFIC CLASS


Import packagename.classname

IMPORT WHOLE PACKAGE


Import packagename.*
Java.util.Scanner
Click to edit Master title style

A class in the java.util Package that helps


programmers handle inputs from the user.
Click to edit Master title style

Create new class


Click to edit Master title style
USER INPUT
Click to edit Master title style

String x;
Scanner s = new Scanner(System.in);

x = s.nextLine();
Click to edit Master title style
Click to edit Master title style
Click to edit Master title style

Create Error
USER INPUT
Click to edit Master title style

• nextLine()
• nextInt()
• nextShort()
• nextLong()
• nextByte()
• nextBoolean()
• nextDouble()
• nextFloat()
Click to edit Master title style
Click to edit Master title style

Decimal not integer


Click to edit Master title style
Click to edit Master title style
Click to edit Master title style

Arithmetic
Operators
ARITHMETIC OPERATORS
Click to edit Master title style

SYMBOL OPERATION RESULT USAGE

+ Addition Sum x+y

- Subtraction Difference x–y

* Multiplication Product x*y

/ Division Quotient x/y

% Modulus Remainder x%y

++ Increment Add 1 x++

-- Decrement Subtract 1 x--


Click to edit Master title style

Change operator
+-*/
Click to edit Master title style

Perform operation
directly
Click to edit Master title style

Perform operation
to variable
Click to edit Master title style
Click to edit Master title style
Click to edit Master title style

Using modulus
Using float
Click to edit Master title style
Click to edit Master title style
Increment
Click to edit Master title style
Decrement
Click to edit Master title style

LESSON
ACTIVITY
SIMPLE CALCULATOR
Click to edit Master title style

Create a program that will make the user input


the 2 numbers and perform one of the arithmetic
operators excluding increment and decrement.

Sample Output:
Num1 : 5
Num2 : 5
Result : 5 + 5 = 10
Click to edit Master title style 1st Solution
Click to edit Master title style 2nd Solution
Click to edit Master title style

User input and


Arithmetic
Operators
Click to edit Master title style

Thank You. ❤

Sir Mark Leslie D. Melendez

You might also like