Sunday, January 25, 2009

How to use for loop in java programming?

//I have here very nice example for forloop.

class forloop
{ //Your class the name of the is 'forloop
public static void main(String[] args) {
for(int x=1; x<=10;x++) { //
System.out.println("Number: " + x);
}

/*
Instructions

int x=1 is your declaration of your variable starts from 1 to 10.
x<=10 is your condition til the condition becomes false.
x++ is your Incrementation in-order your x will move starts 1 to 10.
System.out.println("Number: " + x); is for display Number : 1 to 10

*/

}
}

/*
********OUTPUT**********

Number: 1
Number: 2
Number: 3
Number: 4
Number: 5
Number: 6
Number: 7
Number: 8
Number: 9
Number: 10


*/

Download File

11 comments:

  1. how to make pyramid . .using forloop? can u do this?

    ReplyDelete
  2. and also diamond forloop?

    ReplyDelete
  3. PYRAMID

    for(int i=1; i<= 5 ;i++){
    for(int j=0; j < i; j++){

    System.out.print("*");
    }
    System.out.println("");
    }

    for(int i=5; i>0 ;i--){
    for(int j=0; j < i; j++){

    System.out.print("*");
    }
    System.out.println("");
    }
    ___________________________
    OUTPUT:
    *
    * *
    * * *
    * * * *
    * * * * *
    * * * * *
    * * * *
    * * *
    * *
    *

    ReplyDelete
  4. Hi,
    im a college student and we have a project about java programing,related in loop and array,please help me to build a input of simple games, or any concept,

    ReplyDelete
  5. Thanks for answering some question. Thank you

    ReplyDelete
  6. don't try to a be game programmer first of all you should learn the core concept of java.
    It's not a good idea to start a project using game programming. I suggest you to make a real thing in java.

    ReplyDelete
  7. good day... im having a hard time using loop how can i make a java program to determine the number of digits of an inputted integer??

    please help

    ReplyDelete
  8. hi can you help me do a for loop which out puts two pyramids facing each other?,,, tnx

    ReplyDelete
  9. sir/mon can you also post some code of post test and pre tesvt loop code ,, please
    ]

    ReplyDelete
  10. Replies
    1. what the heck tlaga!!!!!!!!!!!!!!!!

      Delete

 

blogger templates | Make Money Online