हिंदी

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

प्रश्न

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.

संक्षेप में उत्तर
Advertisements

उत्तर

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
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 1.06: Input in Java - EXERCISES [पृष्ठ ६६]

APPEARS IN

अविचल Computer Applications [English] Class 10 ICSE
अध्याय 1.06 Input in Java
EXERCISES | Q V. 3. | पृष्ठ ६६
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×