Conditional - The If Statement

If(you don't know bout if's){
System.out.println(""+ifDefinition);


If statements are pretty cool, they allow us to start adding real logic to our code. Conditionals are pretty easy to implement, but they can get complicated pretty quick.


Here's an example:


int cat = 9;
int dog = 1;
if(cat>dog){
System.out.print("Cats have more lives than dogs.");
}Else{
System.out.print("Dogs have more lives than cats.");


The IF statement will check it's parenthesis for what parameters to check for, and if found to be correct, it will run it's containing function, unless it's conditions are not met, in which case it will run it's counterfunction, the else statement.


For more detail watch the 
DETAILED VIDEO BELOW:











4 comments:

  1. int n1,n2,n3,max;

    n1=Integer.parseInt(box1.getText());
    n2=Integer.parseInt(box2.getText());
    n3=Integer.parseInt(box3.getText());

    if(n1>n2 && n1>n3)
    max=n1;
    else
    if (n2>n1 && n2>n3)
    max=n2;
    else
    if (n3>n2 && n3>n1)
    max=n3;
    box4.setText(""+max);

    what is wrong with this code please answer me
    thanks

    ReplyDelete
    Replies
    1. You don't have any curly brackets.

      Delete
  2. how do you do if statements with string variables?

    ReplyDelete