Академический Документы
Профессиональный Документы
Культура Документы
boolean type for variables is used to store only two values (true
and false)
Memory Requirement : 1 bit
Java does not represent boolean values by 1 and 0 as used in C
Programming language
Every logical and relational expression results in boolean type
value
boolean b = true;
boolean x = a>b; Valid
boolean z = a > b && b > 10 Statements
boolean b = 1;
In-Valid
booelan x = 0;
Statements
5 Object-Oriented Programming (CS F213) Dr. Pankaj Vyas
Java Primitive Types: boolean
if(10) if(10)
printf(Hello); System.out.println(Hello);
else else
printf(Hi); System.out.println(Hi);
char x = a; valid
short s = 20;
int x = 10;
int y = b * s + x;
System.out.println(y);
System.out.println(result);
Convertible Types
char
double float long int short byte
19 Object-Oriented Programming (CS F213) Dr. Pankaj Vyas
Type Casting Example
// File Name TypeCasting.java
class TypeCasting
{
public static void main(String[] args)
{
double d = 65.56;
char x = (char) d; javac TypeCasting.java
System.out.println(x);
java TypeCasting
char y = 'A';
byte b = (byte) y;
System.out.println(b); A
65
float f = (float) 4.56;
System.out.println(f); 4.56
System.out.println(Hello+10); Hello10
System.out.println(10+20); 30
System.out.println(10 + 20 + Object);
30Object
System.out.println(10+20);
1020
System.out.println(10 + 20);
1020
System.out.println(Hello: + 20 + is my age);
Hello 20 is my age
System.out.println(10 + (20 + 40 * 3) + 60); 1014060
System.out.println(10 + (20 + 40 / 4) + 50); 10201050
class Test
{
public static void main(String args[])
{
System.out.print("Hello ");
System.out.print( I am fine");
System.out.println(" It is OK");
System.out.print(Welcome);
}// End of Method
}// End of class Test
Hello I am fine It is OK
Welcome