Computer Science, asked by ramarekha2005, 1 year ago

write a program in Java that determines the value of the coins in a jar and prints the total in rupees and paise. Read integer values that represent the number of 10rs coins, 5rs coins, 2rs coins, 1rs coins, 50 paise coins, 25 paise coins, 20 paise coins, 10 paise coins and 5 paise coins.

Answers

Answered by QGP
13
import java.util.Scanner;
public class JAVA_Program
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
       
        System.out.print("Enter the number of 10 Rupees Coins: ");
        int n1 = sc.nextInt();
       
        System.out.print("Enter the number of 5 Rupees Coins: ");
        int n2 = sc.nextInt();
       
        System.out.print("Enter the number of 2 Rupees Coins: ");
        int n3 = sc.nextInt();
       
        System.out.print("Enter the number of 1 Rupee Coins: ");
        int n4 = sc.nextInt();
       
        System.out.print("Enter the number of 50 Paise Coins: ");
        int n5 = sc.nextInt();
       
        System.out.print("Enter the number of 25 Paise Coins: ");
        int n6 = sc.nextInt();
       
        System.out.print("Enter the number of 20 Paise Coins: ");
        int n7 = sc.nextInt();
       
        System.out.print("Enter the number of 10 Paise Coins: ");
        int n8 = sc.nextInt();
       
        System.out.print("Enter the number of 5 Paise Coins: ");
        int n9 = sc.nextInt();
       
        int sr = (10*n1)+(5*n2)+(2*n3)+n4;
        int sp = (50*n5)+(25*n6)+(20*n7)+(10*n8)+(5*n9);
       
        sr += sp/100;
        sp = sp%100;
       
        System.out.println("Jar contains "+sr+" Rupees "+sp+" Paise");
       
    }
}


QGP: You are welcome :)
ramarekha2005: :>
ramarekha2005: can u plz tell me why have u done sr=sp/100 and sp=sp%100
QGP: sr is Sum of Rupees collected. sp is initially sum of all Paise collected
QGP: sp might be greater than 100. For example,
QGP: if sp=260 then I cannot display output as 260 paise.
QGP: sp/100 will give the quotient [Here 2 for 260] . So, sr += sp/100 adds the complete rupees collected as paise.
QGP: sp%100 gives the remainder when sp is divided by 100. [Here, 60 for sp=260] This value is reassigned to sp. That is why I wrote: sp = sp%100:
ramarekha2005: Oh... I understood....thanks a lot again... I am a grateful debtor for your help :) :) :)
QGP: आपका धन्यवाद! You are welcome :))
Similar questions