Ask Question
18 September, 02:05

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

+1
Answers (1)
  1. 18 September, 02:32
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers