We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Java
- Introduction
- Java If-Else
- Discussions
Java If-Else
Java If-Else
Sort by
recency
|
2058 Discussions
|
Please Login in order to post a comment
** This is also one of the solution for the given problem** if(N%2==0 && (N>1 && N<=5 || N>20)) System.out.println("Not Weird"); else System.out.println("Weird");
**This is solution of the problem **
import java.util.Scanner;
public class Solution {
public static void main (String[] args){
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
if(n%2!=0){
System.out.println("Weird");
}else if(n>1 && n<6 && n%2==1){
System.out.println("Not weird");
}else if(n>6 && n<=20 && n%2==0){
System.out.println("Weird");
}else{
System.out.println("Not Weird");
}
}
}
** Solving the problem this way will cover all events possible, but it is a bit complex for being too concise. **
import java.io.; import java.math.; import java.security.; import java.text.; import java.util.; import java.util.concurrent.; import java.util.regex.*;
public class Solution {
}
This task clearly walks through if-else logic by mapping specific conditions to outcomes, making the decision flow easy to follow. The structured rules feel as precise as handling pay per call life insurance leads, where each condition leads to a clear, predefined result.
This is solution of the problem with 2 different ways: