[[School]] - [[Learning]]
tags: #lecture Links: [[AP Java]] - [[AP Java Lectures]]
- put data type in parentheses before whatever you want to cast
- only "casts" the item immediately next to it
double x - (double) 1 + 1 / 2; // 1.0
double y = 1 + (double) 1 / 2; // 1.5
- you can use parentheses to escape
class Main {
public static void main(Stringp[ args){
double x = 4 / 3;
double y = (double)(125/10);
double z = (double) 28 / 5;
System.out.println(x + " " + y + " " + z);
}
}
Created 09-09-2022, 10:44 AM.