Advertisements
Advertisements
Question
A man spends `1/2` of his salary on food, `1/15` on rent, `1/10` on miscellaneous activities. Rest of the salary is his saving. Write a program to calculate and display the following:
- money spent on food
- money spent on rent
- money spent on miscellaneous activities
- money saved
Take the salary as an input.
Answer in Brief
Solution
import java.util.*;
public class U5_Q3{
public static void main(String args[])
{
Scanner obj = new Scanner(System.in);
double sal, food, rent, misc, save;
System.out.println("Enter the salary");
sal = obj.nextDouble();
food = 1.0 / 2 * sal;
rent = 1.0 / 15 * sal;
misc = 1.0 / 10 * sal;
save = sal − (food + rent + misc);
System.out.println("Money spent on food: " + food);
System.out.println("Money spent on rent: " + rent);
System.out.println("Money spent on misc: " + misc);
System.out. println("Money saved: " + save);
}}
shaalaa.com
Is there an error in this question or solution?