Time: 15 minutes
Purpose: Exploring what happens when you mix decimal and integers
Introduction: You’ve done operations on two identical variable types. What happens when they’re not the same?
Task: Try adding an integer to a double number and printing the result
- Describe what happens
- Attempt to make the addition work by any means
Was playing around with how many decimal digits we can have
int A = 1;
double B = 2.9999999999999999;
double C = 2.999999999999999;
int D;
double E;
D = (int)B + (int)C;
E = B + C;
System.out.println(newLine + "INT ---> " + (int)B + " + " + (int)C + " = " + D);
System.out.println("DOUBLE ---> " + B + " + " + C + " = " + E);
System.out.println("DOUBLE ---> " + (double)A + " + " + C + " = " + E);
Good work. You’ve got the basics.