-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcasting.java
More file actions
31 lines (26 loc) · 1.17 KB
/
Copy pathcasting.java
File metadata and controls
31 lines (26 loc) · 1.17 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
/************************************CASTING************************************/
/* Simply put casting in Java is you telling the compilet that the given data type of of a certain form
or you forcefully converting the data type
example: casting a float or double to an int
*/
public class casting{
public static void main(String[] args){
int myInt = Integer.MIN_VALUE;
byte myByte = Byte.MIN_VALUE;
short myShort = Short.MIN_VALUE;
int myNewIntInt = (myInt / 2);
int myNewIntByte = (myByte / 2);
int myNewIntShort = (myShort / 2);
System.out.println("Div Int Int = " + myNewIntInt);
System.out.println("Div Int Byte = " + myNewIntByte);
System.out.println("Div Int Short = " + myNewIntShort);
//This CASTING needs to be done cause java by default makes the byte short to integers on division
//We gotta tell java that the are not int and to keep them as short and byte
int myNewInt = (myInt / 2); //Casting
byte myNewByte = (byte)(myByte / 2);
short myNewShort = (short) (myShort / 2);
System.out.println("\nDiv Int Int = " + myNewInt);
System.out.println("Div Byte Byte = " + myNewByte);
System.out.println("Div Short Short = " + myNewShort);
}
}