JAVA BUILT-IN PACKAGES
Instructor: KRYSTEL JANE L. AJIAS
INSTANTIATION
Package: import [Link]
Scanner s = new Scanner([Link]);
name = [Link]();
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 [Link];
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 ([Link]);
[Link]("enter age ");
age = [Link]();
[Link]("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