Exception, Unicode and Double checking and printing Exercise
- Write a program that ask the user for the number to print as a unicode character.
- If the user enters a letter, tell the user they entered a letter instead
of a number.
- Print the number as a unicode character by casting it to a char.
- Divide the number by 3. three times. Then multiply that result back by 27.
Print the result with only 2 decimal places using the DecimalFormatter class
- Compare the final result to the original number to see whether they are
the exact same number exactly.
- Compare the final result to the original number to see whether they are
within +/- .001 of each other.
Reminders:
DecimalFormatter object knows: How to print decimals
Package to import: import java.text.DecimalFormat;
How to create a DecimalFormatter for your numbers:
DecimalFormat percentage2 = new DecimalFormat(0.00%);
How to use a DecimalFormatter to print to your screen:
System.out.println(percentage2.format(.308)); // will print 30.80%
Different format options:
0 = required position
# = show it if you have it
% = make it a % (mult by 100)
E = E notation (scientific)
Try/Catch:
- You can stop executing a method with a throw command.
- Create an exception to throw new IllegalArgumentException(tell
about the error);
- You can catch the error in the calling program using a try /catch block.
Try{}
Catch{}