Repository navigation
Expand file tree
/
Copy pathTypePromotionExpression.java
More file actions
81 lines (59 loc) · 2.16 KB
/
Copy pathTypePromotionExpression.java
File metadata and controls
81 lines (59 loc) · 2.16 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// import java.util.*;
// public class TypePromotionExpression {
// public static void main(String[] args){
// char a = 'a';
// char b = 'b';
// char c = a - b; --> error
// System.out.println((int)(b));
// System.out.println((int)(a));
// System.out.println(a);
// // System.out.println(b-a);
// }
// }
// ----------------------------------------------------------------------------------------
// public class TypePromotionExpression {
// public static void main(String[] args){
// short a = 5;
// byte b = 25;
// char c = 'c';
// byte bt = (byte) (a + b + c);
// System.out.println(bt);
// }
// }
// ---------------------------------------------------------------------------------------------
// public class TypePromotionExpression {
// public static void main(String[] args){
// int a = 10;
// float b = 20.25f;
// long c = 25;
// double d = 30;
// double ans = a + b + c + d;
// System.out.println(ans);
// }
// }
// ----------------------------------------------------------------------------------------------
// public class TypePromotionExpression {
// public static void main(String[] args) {
// byte b = 5;
// byte a = (byte) (b * 2);
// System.out.p
// }
// }
// ---------------------------------------------------------------------------------------------------
// public class TypePromotionExpression {
// public static void main(String[] args) {
// byte a = 10;
// char b = 'a'; // ASCII/Unicode value = 97
// short c = 20;
// int d = 50;
// float e = 5.5f;
// double f = 12.34;
// // Expression evaluation:
// // 1. (a * b) me a (byte) aur b (char) int ban jate hain -> result int
// // 2. (d / c) me c (short) int ban jata hai -> result int
// // 3. (f * e) me e (float) double ban jata hai -> result double
// // Final result poora double ban jata hai.
// double result = (a * b) + (d / c) - (f * e);
// System.out.println("Result: " + result);
// }
// }