Practice
Resources
Contests
Online IDE
New
Free Mock
Events New Scaler
Practice
Improve your coding skills with our resources
Contests
Compete in popular contests with top coders
Events
Attend free live masterclass hosted by top tech professionals
New
Scaler
Explore Offerings by SCALER

# If Else

In this problem, you will learn about control flow statements using Java if and if...else statements with the help of examples.

In computer programming, we use the if statement to control the flow of the program. For example, if a certain condition is met, then run a specific block of code. Otherwise, run another code.

An if-else statement has the following logical flow:

For example:

``` class Main {
public static void main(String[] args) {

int number = 0;

// checks if number is greater than 0
if (number > 0) {
System.out.println("The number is positive.");
}

// checks if number is less than 0
else if (number < 0) {
System.out.println("The number is negative.");
}

// if both condition is false
else {
System.out.println("The number is 0.");
}
}
}

Output

The number is 0.
```

In the above example, we are checking whether the number is positive, negative, or zero.

Here, we have two condition expressions:

• number > 0 - checks if the number is greater than 0
• number < 0 - checks if the number is less than 0

Here, the value of the number is 0. So both the conditions evaluate to false. Hence the statement inside the body of else is executed.

Given an integer M perform the following conditional actions:

• If M is multiple of 3 and 5 then print "Good Number" (without quotes).
• If M is only multiple of 3 and not of 5 then print "Bad Number" (without quotes).
• If M is only multiple of 5 and not of 3 then print "Poor Number" (without quotes).
• If M doesn't satisfy any of the above conditions then print "-1" (without quotes).

Hints
• Complete Solution

## Discussion

Free Mock Assessment
Fill up the details for personalised experience.
Phone Number *
OTP will be sent to this number for verification
+1 *
+1
Change Number
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
*Enter the expected year of graduation if you're student
Current Employer
Company Name
College/University Name
Job Title
Job Title
Software Development Engineer (Backend)
Software Development Engineer (Frontend)
Software Development Engineer (Full Stack)
Data Scientist
Android Engineer
iOS Engineer
Devops Engineer
Support Engineer
Research Engineer
Engineering Intern
QA Engineer
Co-founder
SDET
Product Manager
Product Designer
Backend Architect
Program Manager
Release Engineer