Ask Question
2 July, 11:17

Write a program to input money in cents from user, example 12745 and display the one dollar bills and the cents. Submit source code.

+5
Answers (1)
  1. 2 July, 14:16
    0
    import java. util.*; / /This is used to import the Scanner

    class Main {

    public static void main (String[] args) {

    System. out. println ("Hello world!");

    Scanner ValCents = new Scanner (System. in);

    System. out. println ("Enter Number:");

    int user_input = ValCents. nextInt ();

    int result = user_input/100; / / This one will solve for the one dollar bills.

    int remain = user_input % 100; / / This one will get the remainder of cents.

    System. out. println (result + " One Dollar Bills");

    System. out. println (remain + " Cents");

    }

    }

    Remember that you need to get the amount of dollar bills separately from the number of cents. This is because the int variable will always return the whole value of the number. The modulo is used to get the variable of the cents as the whole number is already taken by the "result".
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a program to input money in cents from user, example 12745 and display the one dollar bills and the cents. Submit source code. ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers