Question 3 [12 marks]:
double num1 = 1234567.456, num2 = 123.456, num3= 123.456, num4 = 123456.789;
int num5 = 123456;
String name="James";
Write a program that includes the following statements:
1. A printf statement that displays the value of num1 formatted as: 1,234,567.46
2.
A printf statement that displays the value of num2 rounded to one decimal place, in a field that is ten spaces wide (Do not use comma separators).
3.
A printf statement that displays the value of num3 padded with leading zeros, in a field that is eight spaces wide, rounded to one decimal place (Do
not use comma separators).
A printf statement that displays the value of num4, left-justified, with comma separators, in a field that is 20 spaces wide, rounded to two decimal
4.
places.
5.
A printf statement that displays the value of num5 in a field that is 10 spaces wide, with no comma separators.
A printf statement that displays the value of name in a field that is 20 spaces wide.
6.
NOTE:
• Write the comments on your program whenever necessary;
• Use proper indentation to make your code read easily (no spaghetti coding please);
• You can share ideas with others, but not code. You must write your program independently. If you are found to copy each other's program or copy from
online, you will get negative total of the assignment on the whole assignment even if cheating on one question;
• Follow submission instructions (see below for how to submit your assignment online) properly. Late assignments will not be accepted. Please don't
submit your assignments to Dr. Srivastava or John Chen via email.
SUBMISSION: