Day 3: Intro to Conditional Statements

Sort by

recency

|

1790 Discussions

|

  • + 0 comments

    import java.util.Scanner; public class WeirdOrNot { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); if (N % 2 == 0) { if ((N >= 2 && N <= 5) || N > 20) { System.out.println("Not Weird"); } else if (N >= 6 && N <= 20) { System.out.println("Weird"); } } else { System.out.println("Weird"); } } }

  • + 0 comments
    if N % 2 != 0:
        print('Weird')
    elif N % 2 == 0 and 2 <= N <= 5:
        print('Not Weird')
    elif N % 2 == 0 and 6 <= N <= 20:
        print('Weird')
    else:
        print('Not Weird')
    
  • + 1 comment
            if(N%2==0){
                if(N<=5 || N>20){
                    System.out.println("Not Weird");
                }
                else if(N>=6 && N<=20){
                    System.out.println("Weird");
                }
            }
            else{
                System.out.println("Weird");
            }
    
  • + 0 comments

    import java.io.*;

    public class Solution { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));

        int N = Integer.parseInt(bufferedReader.readLine().trim());
    
    
        String weird=(N%2!=0)?"Weird":N>=6&&N<=20?"Weird":"Not Weird";
        System.out.println(weird);
        bufferedReader.close();
    }
    

    }

  • + 0 comments

    Use an uppercase N