15,936,802 members
See more:
How to construct a program
that will require the user to input
their salary and your program can
calculate the increment in salary that
will obtain based on the table below.
Using if----else selection control statement.

Salary Increment

N 800 - N1000 2%

N 101 - N2000 5%

N 201 - N4000 8%

N 400 > 10%

What I have tried:

I have tried this code but i wants to know weither i am correct or not. Thanks

Java
```import java.util.Scanner;
public class Question2
{
public static void main(String [] args)throws IOException
{
float salary;
double increment;
Scanner scanner = new Scanner(new InputStreamReader(System.in));

salary = scanner.nextFloat();

if ((salary >=800) && (salary <=1000))

{
increment=(2 / salary)*100;
System.out.println("\nPercentage increment is: " + increment + "\n");
}
else if ((salary >=101) && (salary <=2000))
{
increment=(5 / salary)*100;
System.out.println("\nPercentage increment is: " + increment + "\n");
}
else if ((salary >=201) && (salary <=4000))
{
increment=(8 / salary)*100;
System.out.println("\nPercentage increment is: " + increment + "\n");
}
else if (salary > 400 )
{
increment=(10 / salary)*100;
System.out.println("\nPercentage increment is: " + increment + "\n");
}
else
System.out.println("\nNo More Increment For This Salary\n");

}
}```
Posted
Updated 11-Feb-23 7:51am
v3
[no name] 1-May-13 21:04pm
"i have tried this code but i wants to know weither i am correct or not", if it works as you expect it to then it is correct. If it does not work as you expect it to then it is not correct.
Philippe Mori 2-May-13 0:09am
Are you sure that your condition are the right ones. I think that some numbers are incorrect. For example 101 is probably 1001... It would make sense only if salary is an integer too since people with a salary in between would not have the augmentation. If original number are used things are also inconsistant...
P Uday kishore 2-May-13 1:49am
is that working fine?if not we can look into it further..
Sudhakar Shinde 2-May-13 4:02am
If salary is 900 then it will satisfy almost all the conditions. Please have a look at these conditions first.
@sunusi1 4-May-13 13:36pm
you have talked true, the range of salary is
800-1000
1001-2000
2001-4000
400>

## Solution 1

You should check the logic behind your code. Do you realize salary ranges overlap?
As Sudhakar Shinde already pointed out, a salary of `900` would satisfy all your conditions (while due to the `else if` chain, only first condition's statement would be executed.