0% found this document useful (0 votes)
21 views6 pages

Lesson 2. Java Built-In Packages

The document discusses Java built-in packages, including how to import and instantiate the Scanner package to get user input using methods like nextLine() and nextInt(). It also covers arithmetic operators like addition, subtraction, multiplication, and division. Code samples are provided to demonstrate getting user input to perform calculations and display output.

Uploaded by

Silhig Lanot
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
0% found this document useful (0 votes)
21 views6 pages

Lesson 2. Java Built-In Packages

The document discusses Java built-in packages, including how to import and instantiate the Scanner package to get user input using methods like nextLine() and nextInt(). It also covers arithmetic operators like addition, subtraction, multiplication, and division. Code samples are provided to demonstrate getting user input to perform calculations and display output.

Uploaded by

Silhig Lanot
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 6

JAVA BUILT-IN PACKAGES

Instructor: KRYSTEL JANE L. AJIAS


INSTANTIATION
Package: import java.util.Scanner

Scanner s = new Scanner(System.in);


name = s.nextLine();

Note: nextLine is intended for String only.


TO GET USER INPUT

• nextLine() • nextByte()
• nextInt() • nextBoolean

• nextShort() • nextDouble()
• nextFloat()
• nextLong()
ARITHMETIC OPERATOR
OPERATION SYMBOL OUTPUT SYNTAX

+ Addition Sum X+y

- Subtraction Difference X-y

* Multiplication Product X*y

/ Division Quotient X/y

% Modulus Remainder X%y

++ Increment Plus 1 X++

-- Decrement Minus 1 X--


package tutorial;
import java.util.Scanner;
public class Tutorial {

public static void main(String[] args) {

String name="kai";
char x= 'a';
int age=6;

Sample Code double weight= 45.5;


float hi=45354.5f;

Scanner scan = new Scanner (System.in);


System.out.println("enter age ");
age = scan.nextInt();

System.out.println("You are " +age +" years old");


}
}
EXERCISE 2. ADDITION
Create a Java program that ask the user to input 2 numbers both whole number and decimal
number and perform addition then increment the final answer by one. Display the output.

Sample output:

First number is: 5


Second number is: 7

Sum is: 13

You might also like