Day 3: Intro to Conditional Statements

Sort by

recency

|

1811 Discussions

|

  • + 0 comments

    C++

        if(N % 2 !=0){
            printf("Weird" );
        }else if(N % 2 !=1 && N>=2 && N<=5){
            printf("Not Weird");
        }else if(N % 2 !=1 && N>=6 && N<=20){
            printf("Weird");
        }else if(N % 2 !=1 && N>=20 && N<=100){
            printf("Not Weird");
        }
        return 0;
    }
    
  • + 0 comments

    Java solution if(N % 2 ==0){ if( N < 5 || N > 20){ System.out.println("Not Weird"); }else{ System.out.println("Weird"); } }else{ System.out.println("Weird"); }

  • + 0 comments
     my java solution(simple and clean):
    
         if (N%2==0) {
            if (N>=6 && N<=20) {
                System.out.println("Weird");
            } else {
                System.out.println("Not Weird");
            }
    
        } else {
            System.out.println("Weird");
        }
    
  • + 0 comments
    if N%2 == 0 {
        if 2 <= N && N <= 5 || N > 20 {fmt.Print("Not ")}
    }
    fmt.Println("Weird")   
    
  • + 0 comments

    ** Here is the solution in 2 if statements **

    if ( (N % 2) != 0 || (N %2 ==0 && (N >=6 && N<= 20)) ) cout << "Weird" << endl; else if (N %2 ==0 && ((N >=2 && N<= 5)||( N >=20))) cout << "Not Weird" << endl;