How to Get the Next String Input From in Java

A Java "for" loop iterates through each array value in the array indexes. To get the next string in the index order, increment the index pointer by one. Java loops are used in code to loop through several values, print the values or evaluate them to create calculations. You can use any increment variable for your loop, but you must use a different value for each embedded loop function.

Instructions

    • 1

      Launch your Java editor and open the desktop project you want to edit. Double-click the Java source code file you want to use to add the loop.

    • 2

      Create the "for" loop with the increment variable. The following for loop uses "i" to increment and iterate through the loop:

      for (int i = 0; i<array.length;i++) {
      }

      In this example, the "for" loop iterates through all array elements until it reaches the end of the array's length. The "i++" increments the value by one after each loop.

    • 3

      Add the content in the "for" loop to get the next string value after each pass through the loop. The following code prints each array string value:

      System.out.println("Next value: " + array[i]);

Related Searches:

References

Comments

Related Ads

Featured