Professional Documents
Culture Documents
Assignment Statement
Eg. a=2; a=b=2;
Eg. f=6; g=f++; //g has 6 and f has 7
Eg. f=6; g=++f; //g has 7 and f has 7
Data Types
Primitive Types
Arithmetic Operators
1. + Addition - Subtraction *
Multiplication / Division % Modules
++ Increment by 1 -- Decrement by 1
Operator Precedence
- Bracket, Of, Division, Multiplication, Addition, Subtraction
Methods that return Scans Text and Numbers using Scanner class
nextBoolean(): Scans the next token of the input into a boolean value and returns that value.
nextByte() :Scans the next token of the input as a byte.
nextInt() :Scans the next token of the input as an int.
nextLong() :Scans the next token of the input as a long.
nextFloat() :Scans the next token of the input as a float.
next() :Scans the next token of the input as a word.
nextLine() :Advances this scanner past the current line and returns the input that was
skipped.
Casting
• Can convert a value of one type to another by using an explicit cast. Boolean variables
can never be cast. Object can be cast to another class if they are instances of that class
or any of its subclasses.
e.g String x = (String)10; // error
Example (3)
public class TestCast
{ public static void main (String[] args)
{ float x = 10.3f; int y = 3;
int i = (int)(x/y); System.out.println ("i = "+i); }
}
Assignment
1. Write a program to input student record (name, sex, mark) from keyboard and
displays student record data.