(2x5=10)
1. Write a java statement to check if marks are more than 50 but less than 90
Answers
Java statement:
if(marks > 50 && marks < 90)
More information:
1) If statement
if(condition)
{
Statement(s);
}
Example:
if(n % 2 == 0)
{
System.out.print("Even number");
}
2) Nested if statement
if(condition_1)
{
Statement_1(s);
if(condition_2)
{
Statement_2(s);
}
}
Example:
if(n > 20)
{
System.out.println("Number is greater than 20");
if(n < 80)
{
System.out.println("Number is less than 80");
}
}
3) If else statement
if(condition)
{
Statement(s);
}
else
{
Statement(s);
}
Example:
if(n % 2 == 0)
{
System.out.println("Even number");
}
else
{
System.out.println("Odd number");
}
4) If-else-if statement
if(condition_1)
{
Statement(s);
}
if else(condition_2)
{
Statement(s);
}
if else(condition_3)
{
Statement(s);
}
.
.
.
else
{
Statement(s);
}
Example:
if(n > 0)
{
System.out.println("Positive");
}
if else(n < 0)
{
System.out.println("Negative");
}
else
{
System.out.println("Zero");
}