Sort by

recency

|

2058 Discussions

|

  • + 0 comments

    ** 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");

  • + 0 comments

    **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");

    }

    }

    }

  • + 0 comments

    ** 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 {

    private static final Scanner scanner = new Scanner(System.in);
    
    public static void main(String[] args) {
        int n = scanner.nextInt();
        scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
    
        /*----------------------------------------------------------------------------
    
            Case 0: Range of n -> (0-100)
                This problem has 4 main cases 
                    if n -> odd  : Weird
                    if n -> even : 
                        Range of n (2-5)  : Not Weird   
                        Range of n (6-20) : Weird
                        Range of n (<20)  : Not Weird
    
    
        ----------------------------------------------------------------------------*/
    
        while( n >= 0 && n <=100 ){
            if( n%2 != 0 || (n%2 == 0 && n >= 6 && n <= 20)){
                System.out.println("Weird");
                break;
            }
            else if( n%2 == 0  && ((n >= 2 && n <= 5) || (n > 20)) ) {
                System.out.println("Not Weird");
                break;
            }
        }
        scanner.close();
    }
    

    }

  • + 0 comments

    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.

  • + 0 comments

    This is solution of the problem with 2 different ways:

        public static void main(String[] args) {
            int N = scanner.nextInt();
            scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
            String message = "";
            // Way One: Is Complex & Concise 
            // if (N % 2 != 0 || (N % 2 == 0 && (N>=6 && N<=20))) message = "Weird";
            // else if (N % 2 == 0 && (N >= 2 && N <=5) || (N % 2 == 0 && N>20)) message = "Not Weird";
            
            // Way Two: More Readable
            if (N % 2 != 0) message = "Weird"; // Odd
            else {
                // Even
                if (N >=2 && N <= 5) message = "Not Weird";
                else if (N>=6 && N<=20) message = "Weird";
                else message = "Not Weird";
            }
            
            System.out.println(message);
            scanner.close();
        }