I am having a little trouble figuring out how to assign a variable (dollars) to the numbers left of the decimal and how to assign a variable (cents) to the right of the decimal. The only parts of the code I can modify are those 2 assignment statements because it is a homework question. The user inputs something like 123.45
Thanks for any help.
Expand|Select|Wrap|Line Numbers
- import java.util.Scanner;
- public class ApplicationSkel
- {
- public static void main(String[] args)
- {
- double amount;
- int dollars, cents;
- Scanner scan = new Scanner(System.in);
- System.out.print("Enter your purchase $");
- amount = scan.nextDouble();
- dollars = ________;
- cents = ________;
- System.out.print("You entered " + dollars + " dollars and " + cents + ".");
- }
- }