Self-Learning Module
Outcomes Covered
- Know when automatic type promotion will occur
- Use type casting to explicitly convert between primitive types
- Convert from
String
to primitive types
- Convert from privimitive types to
String
s
Watch
Do
- Add the appropriate code to complete the following program:
public static void main(String[] ignored) {
System.out.println("Enter an integer");
Scanner in = new Scanner(System.in);
String first = in.next();
// Convert this into an integer called firstNum
System.out.println("Enter an double");
String second = in.next();
// Convert this into a double called secondNum
System.out.println(firstNum + " goes into " + secondNum + " " +
secondNum/firstNum + " times");
}
- In Canvas submit a screenshot of your completed program running similar to this screenshot:
Bonus Material (optional)