English

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: - Computer Applications

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:

  1. money spent on food
  2. money spent on rent
  3. money spent on miscellaneous activities
  4. money saved

Take the salary as an input.

Answer in Brief
Advertisements

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?
Chapter 1.06: Input in Java - EXERCISES [Page 66]

APPEARS IN

Avichal Computer Applications [English] Class 10 ICSE
Chapter 1.06 Input in Java
EXERCISES | Q V. 3. | Page 66
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×