- Exercise-1: Echoing words in Java
- Exercise 2: Inputting and Echoing integer and string entered by user
- Exercise-3: How to use If Statement in Java Programming
- Exercise-4: How to Use If-ElseStatement in Java Programming
- Exercise-5: Using Multi If and Else Statement in Java Programming
- Exercise-6: Write a program which will represent the entire relational operators in Java Programming.
- Exercise-7: Write a program to demonstrate the logical operators in Java.
- Excercise-8: Write a Program Using Conditional Operator.
- Exercise-9: Java Exercise of IF and SWITCH
- Exercise-10: Java Exercise of While, Do-While and For Loop
- Exercise-11: Java Misc. Excercise(1-10)
- Exercise-11: Java Misc. Exercise(11-19)
- Exercise-11: Java Misc. Exercise(20-25)
Showing posts with label for. Show all posts
Showing posts with label for. Show all posts
Friday, February 8, 2013
Excercise between W1 and W3
Week-3: 3.5: For Loop
For:
As we mentioned earlier, the programming you are doing now is sequential
programming. This means that flow is downward, from top to bottom, with every line of
code being executed, unless you tell Java otherwise.
You saw in the last section that one way to "tell" Java not to execute every line is by
using IF Statement to section off areas of code.
Another way to interrupt the flow from top to bottom is by using loops. A programming
loop is one that forces the program to go back up again. If it is forced back up again
you can execute lines of code repeatedly.
As an example, suppose you wanted to add up the numbers 1 to 10. You could do it quite
easily in Java like this:
int addition = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10;
But you wouldn't really want to use that method if you needed to add up the numbers 1
to a 1000. Instead, you can use a loop to go over a line of code repeatedly until you've
reached 1000. Then you can exit the loop and continue on your way.
As we mentioned earlier, the programming you are doing now is sequential
programming. This means that flow is downward, from top to bottom, with every line of
code being executed, unless you tell Java otherwise.
You saw in the last section that one way to "tell" Java not to execute every line is by
using IF Statement to section off areas of code.
Another way to interrupt the flow from top to bottom is by using loops. A programming
loop is one that forces the program to go back up again. If it is forced back up again
you can execute lines of code repeatedly.
As an example, suppose you wanted to add up the numbers 1 to 10. You could do it quite
easily in Java like this:
int addition = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10;
But you wouldn't really want to use that method if you needed to add up the numbers 1
to a 1000. Instead, you can use a loop to go over a line of code repeatedly until you've
reached 1000. Then you can exit the loop and continue on your way.
Visit for Details
Subscribe to:
Posts (Atom)