If Else Statement

# If Else statement Example

Want to learn quickly?
Try one of the many quizzes. More than Java 400 questions with detailed answers.

• Anonymous says:

how to use if else statement by making a pingpong games.

• Anonymous says:

uhmm…how can you compare 4 different statements using if else…that was exam yesterday… and i wasn’t able to answer it…please help me…thanks a lot…the problem was…. making a program that would show numbers if they are odd or even and if they are negative or a positive odd/even number…the condition is…input a positive or negative number…numbers range from -100 to 0 and 0 to +100

• Palani Kumar A says:

public class oddeven
{
public static void main(String args[])
{
System.out.println(“the odd and even number in between -100 to 100:”);
int num1=100;
if(num1!=0)
{
System.out.print(“the positive even numbers are:”+” “);
for(int i=0;i<num1;i++) {=”” if(i%2=”=0)” system.out.print(i+”=”” “);=”” }=”” system.out.println();=”” system.out.print(“the=”” positive=”” odd=”” numbers=”” are:”+”=”” “);=”” for(int=”” i=”0;i&lt;num1;i++)” {=”” if=”” (i%2=”=0)” continue;=”” else=”” system.out.print(i+”=”” “);=”” }=”” }=”” int=”” num2=”-100;” if(num2<0)=”” {=”” system.out.println();=”” system.out.print(“the=”” negative=”” even=”” numbers=”” are:”+”=”” “);=”” for(int=”” i=”0;i”>num2;i–)
{
if(i%2==0)
System.out.print(i+” “);
}
System.out.println();
System.out.print(“the negative odd numbers are:”+” “);
for(int i=0;i>num2;i–)
{
if(i%2==0)
continue;
else
System.out.print(i+” “);
}
}
}
}

• Anonymous says:

how to use if-else statement in converting the distance in km to miles,yard,meter and feet?

• Anonymous says:

I have one doubt. Is an else statement needed really here?? As per the explanation, if continue statement is given;it will skip the rest of the statements in the loop of the current iteration.So without an else aslo it will work correctly. Can u please clarify.

• Palani Kumar A says:

we given condition if(i==0),the ‘i’ is zero.then condition is true, i will write the ‘continue’ statement.the continue statement to continue the task but else statement, i will used for print the false condition.but i can’t write the print statement in the continue statement.

• Anbu Ruzzo says:

interface
example