Sunday, May 8, 2011

8. Flow of Control

This is the part where you learn to design the 'Artificial Intelligence' of the program. ALL the logic of the program depends on how the flow of control is maintained by it.

Let us first see the logical operators available to us in Java:
  1. == : This is the 'equals' operator. You can use this to check if two numbers or characters are equal.
  2. >= : This is the 'greater-than/equals' operator.
  3. <= : This is the 'less-than/equals' operator.
  4. < : This is the 'less than' operator.
  5. > : This is the 'greater than' operator.
  6. ! : This is the 'not' operator. It is used in conjunction with the other operators. eg: '!=' stands for 'does not equal'.
Now let us take a scenario:
Let us make a grade-calculator. It will take the marks(out of ten) as input, and print the
following results:
  1. 9 or 10: A+
  2. 7 or 8: A
  3. 6: B
  4. 5: C
  5. 4: D
  6. <4: F
This is how you can do it:
__________________________________________________________________

Now that's pretty simple to understand, isn't it? Leave me a comment if there is absolutely ANYTHING that you would like to ask.

2 comments:

  1. how are printIn and print different?

    ReplyDelete
  2. oops! sorry, not been active for some time.

    The 'print' statement simply prints out the message, whereas the 'println' statement prints the message, and takes the cursor to the next line.

    ie anything printed AFTER the current println statement will be printed on the next line.

    eg:
    _________________________________
    System.out.print("Hello ");
    System.out.print("World");

    Hello World
    _________________________________

    System.out.println("Hello ");
    System.out.println("World");

    Hello
    World
    _________________________________

    ReplyDelete