Day 3: Intro to Conditional Statements

Sort by

recency

|

1791 Discussions

|

  • + 0 comments

    For C Language

    int main() { int N = parse_int(ltrim(rtrim(readline()))); if (N>=1 && N<=100) { if (N%2!=0) printf("Weird"); else { if ((N%2==0) && (N>=2 && N<=5)) printf("Not Weird"); else { if ((N%2==0) && (N>=6 && N<=20)) printf("Weird"); else { if ((N%2==0) && (N>20)) printf("Not Weird"); } } } } else printf("Not a positive integer."); return 0; }

  • + 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();
    }
    

    }