Computer Science, asked by HeroicAyush, 1 year ago

Anyone pls solve this

Attachments:

LuckyYadav2578: in which language
HeroicAyush: Java 4.1.4
HeroicAyush: Java

Answers

Answered by sikhi
2

Answer:

package com.sample.sample2;

import java.util.Scanner;

public class Main {

   public static void main(String[] args) {

       Scanner scan=new Scanner(System.in);

       System.out.println("Enter name:");

      String name=scan.next();

       System.out.println("Enter basic salary:");

       double basic=scan.nextDouble();

       double da=0,sa=0,grossSalary;

   if(basic>=10000){

       da=0.1*basic;

       sa=0.05*basic;

   }

    else if(basic>=20000&&basic<=10001){

           da=0.12*basic;

           sa=0.08*basic;

       }

   else if(basic>=30000&&basic<=20001){

       da=0.15*basic;

       sa=0.1*basic;

   }

   else if(basic>=20000){

       da=0.2*basic;

       sa=0.12*basic;

   }

   else System.out.println("error!!!");

   grossSalary=basic+da+sa;

       System.out.println("Name\t\tBasic\t\tDA\t\tSpl Allowance\t\tGross Salary");

       System.out.println(name+"\t\t  "+basic+"\t\t"+da+"\t\t"+sa+"\t\t  "+grossSalary);

 }

}


HeroicAyush: Can we use multiple- If.
HeroicAyush: If yes then please solve it.
sikhi: yes but else if ladder is the most effective way of solving this question
sikhi: if you want to use multiple if then just remove else from each statement and from last also
Similar questions