Session 2: Section A, 3pm To 5:00 PM Data Types in Java: Class Notes by DR B P Sharma - 880060025
Session 2: Section A, 3pm To 5:00 PM Data Types in Java: Class Notes by DR B P Sharma - 880060025
in | 880060025
Integrals
All numbers without decimal are called integrals.
By default such numbers of int type. Use l or L with long as
suffix.
int num=6;
long num=6L;
Types of Integrals
1. Decimal – 0 to 9, default
2. Octal – 0 to 7. Start with 0
3. Hexa Decimal – 0 to 9, A-F. Starts with 0x or 0X
4. Binary – 0 and 1. Starts with 0b or 0B
Use underscore (_) as number separator
int num=45_67_234;
int x=0B1111_0011_0011;
Boolean Literal
Can have true or false only
boolean rented=false;
Getting data input from user
Java provides two methods for data input from user
1. Using java.util.Scanner class
2. Using java.io.BufferedReader class
Scanner class
- Used to input any kind of data from user using built-in
methods
o String next()
o int nextInt()
o float nextFloat()
o double nextDouble()
- We need to create the instance of Scanner class before
calling its methods
Scanner s=new Scanner(System.in);
Example
Write a program to input name and age of a person and check
it to be valid voter.
import java.util.Scanner;
Assignment
WAP to input three numbers and show the biggest one.
WAP to input 2 numbers and print all prime numbers in
the range.
WAP to input a number and reverse print it.