forked from Nabin-joshi/java_notes_and_programs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
widening_typeCasting_overflow.java
57 lines (48 loc) · 1.19 KB
/
widening_typeCasting_overflow.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.util.*;
public class widening_typeCasting_overflow {
public static void main(String[] args) {
// Widening
int a= 10;
float f= a;
System.out.println(a);
System.out.println(f);
// Narrowing(Typecasting)
int b=20;
float fl= (float) (b *10.5);
float F = 1.5F;
int c= (int) F;
System.out.print(c);
System.out.println(fl);
// Overflow
int d=150;
byte e = (byte) d;
System.out.println(d);
System.out.println(e);
// Adding Lower Type
byte g=10;
byte h= 20;
byte sum= (byte) (g+h);
System.out.println(sum);
byte j=120;
int k=20;
// implicit conversion
k=j;
System.out.println(k);
// explicit conversion
j=(byte)k;
System.out.println(j);
int l=10;
int y=20;
System.out.println(++l);
String str = "raar", nstr="";
char ch;
for(int i=0;i<str.length();i++){
ch=str.charAt(i);
nstr =ch+nstr;
}
System.out.println(nstr);
if(str.equals(nstr)){
System.out.println("Plaindrome");
}
}
}