KnowledgeBoat Logo

Computer Applications

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.

Java

Input in Java

63 Likes

Answer

import java.util.Scanner;

public class KboatSalary
{
    public static void main(String args[]) {
        
        Scanner in = new Scanner(System.in);
        
        System.out.print("Enter the Salary: ");
        float salary = in.nextFloat();
        
        float foodSpend = salary / 2;
        float rentSpend = salary / 15;
        float miscSpend = salary / 10;
        float savings = salary - (foodSpend + rentSpend + miscSpend);
        
        System.out.println("Money spent on food: " + foodSpend);
        System.out.println("Money spent on rent: " + rentSpend);
        System.out.println("Money spent on miscellaneous: " + miscSpend);
        System.out.println("Money saved: " + savings);
    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of A man spends (1/2) of his salary on food, (1/15) on rent, (1/10) on miscellaneous. Rest of the salary is his saving. Write a program to calculate and display the following: (a) money spent on food (b) money spent on rent (c) money spent on miscellaneous (d) money saved Take the salary as an input.

Answered By

32 Likes


Related Questions