Results 1 to 3 of 3
Like Tree2Likes
  • 1 Post By jim829
  • 1 Post By MarkLearningJava

Thread: If Statements

  1. #1
    Join Date
    Jun 2013
    Location
    United States
    Posts
    7
    Rep Power
    0

    Post If Statements

    I am a beginner in Java and I was wondering if someone could help me break down the if-then-else statement below. All replies are appreciated. Thank you in advance for your help.

    Java Code:
    public class IfStatements {
        public static void main(String[] args) {
            int number = 1;
                if (number == 1) {
                    System.out.println("The number is 1.");
                } else {
                    System.out.println("The number is not 1.");
                }
        }
    }
    Last edited by MarkLearningJava; 06-28-2013 at 03:31 AM.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    2,935
    Rep Power
    4

    Default Re: If Statements

    Welcome to the forum. First, please put your code between tags. It makes it more readable by formatting. This and other useful information is in the Forum guides which you should read.

    Java Code:
    public class IfStatements {
        public static void main(String[] args) {
            int number = 1;
                if (number == 1) {
                    System.out.println("The number is 1.");
                } else {
                    System.out.println("The number is not 1.");
                }
        }
    }
    The if statements just take an expression using relational operators. If the expression evaluates to true then the following statement or block is executed. If the statement or block is followed by an else clause, then that statement or block will be executed if the if clause evaluated to false.

    Since you are learning Java I highly recommend visiting the tutorials link in my signature.

    Regards,
    Jim
    MarkLearningJava likes this.
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    Join Date
    Jun 2013
    Location
    United States
    Posts
    7
    Rep Power
    0

    Post Re: If Statements

    Quote Originally Posted by jim829 View Post
    Welcome to the forum. First, please put your code between tags. It makes it more readable by formatting. This and other useful information is in the Forum guides which you should read.

    Java Code:
    public class IfStatements {
        public static void main(String[] args) {
            int number = 1;
                if (number == 1) {
                    System.out.println("The number is 1.");
                } else {
                    System.out.println("The number is not 1.");
                }
        }
    }
    The if statements just take an expression using relational operators. If the expression evaluates to true then the following statement or block is executed. If the statement or block is followed by an else clause, then that statement or block will be executed if the if clause evaluated to false.

    Since you are learning Java I highly recommend visiting the tutorials link in my signature.

    Regards,
    Jim
    Thank you very much, Jim, for showing me how to properly display my code by putting it in between tags. I have edited my forum post so that my code displays properly. Your explanation for the if-then-else statement is well written. I appreciate how you took the time out of your day to respond to this thread and I will check out the Java tutorials link in your signature.
    DarrylBurke likes this.

Similar Threads

  1. If statements
    By Joshua.Robinson in forum New To Java
    Replies: 10
    Last Post: 11-15-2012, 09:41 AM
  2. Help with if else statements
    By np2392 in forum New To Java
    Replies: 2
    Last Post: 09-24-2010, 01:25 AM
  3. if else statements
    By sweetpea123 in forum New To Java
    Replies: 4
    Last Post: 04-12-2010, 07:02 PM
  4. age: using if statements
    By yasmin k in forum New To Java
    Replies: 2
    Last Post: 10-04-2009, 09:50 PM
  5. Help with if-else statements
    By porchrat in forum New To Java
    Replies: 4
    Last Post: 03-23-2009, 04:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •