Programming Log - Day 3 - 29/06/2018 - s9f10 - Java Basics - if and else , logical operators


//if and else statements and rational operators

package ifandelseStatements;

import java.util.Scanner;

public class main {

    public static void main(String[] args) {

    Scanner input = new Scanner(System.in);
        System.out.println("Enter a number:");
        
        int i = input.nextInt();
        
        
    if(i == 1)
    {
        System.out.println("ONE");
    }

    else if(i == 2)
    {
        System.out.println("TWO");
    }

    else if(i == 3)
    {
        System.out.println("THREE");
    }

}
}

Result:


// logical operators "and" and "or"

package logicaloperators;

public class main {

    public static void main(String[] args) {

        int subject1 = 20 ;
        int subject2 = 60 ;
        
        if(subject1 > 15 && subject2 > 45)
        {
            System.out.println("the statement is true");
        }
        else
        {
            System.out.Println("the statement is false");
        }
        
    }
    
}

Result:

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now
Logo
Center