Repository navigation
Expand file tree
/
Copy pathTypeCasting.java
More file actions
60 lines (43 loc) · 1.93 KB
/
Copy pathTypeCasting.java
File metadata and controls
60 lines (43 loc) · 1.93 KB
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
58
59
60
// public class TypeCasting {
// public static void main(String[] args){
// double x = 10.85;
// int y = (int) x;
// System.out.println(y);
// }
// }
// ---------------------------------------------------------------------------------------------------
// public class TypeCasting {
// public static void main(String[] args){
// int largeNumber = 130;
// byte byteNumber = (byte) largeNumber;
// System.out.println("Byte value is:" + byteNumber);
// }
// }
// ___________________________________________________________________________________________________
// public class TypeCasting {
// public static void main(String[] args){
// double valDouble = 150.99;
// int valInt = (int) valDouble;
// System.out.println("Origina value :" + valDouble);
// System.out.println("Casted value :" + valInt);
// }
// }
// ---------------------------------------------------------------------------------------------------
// public class TypeCasting {
// public static void main(String[] args) {
// // 1. Implicit / Widening Casting (Automatic)
// // Chhote data type se bade data type me convert hona (int -> double)
// int num = 25;
// double doubleNum = num;
// System.out.println("--- Widening (Implicit) Casting ---");
// System.out.println("Integer value: " + num);
// System.out.println("Converted to Double: " + doubleNum);
// // 2. Explicit / Narrowing Casting (Manual)
// // Bade data type se chhote data type me convert karna (double -> int)
// double price = 99.75;
// int roundedPrice = (int) price; // Manual casting zaroori hai
// System.out.println("\n--- Narrowing (Explicit) Casting ---");
// System.out.println("Double value: " + price);
// System.out.println("Converted to Integer: " + roundedPrice);
// }
// }