Answers for "java loops"

31

for loop java

// Starting on 0:
for(int i = 0; i < 5; i++) {
  System.out.println(i + 1);
}

// Starting on 1:
for(int i = 1; i <= 5; i++) {
  System.out.println(i);
}


// Both for loops will iterate 5 times,
// printing the numbers 1 - 5.
Posted by: Guest on February-18-2020
57

java for loop

for(int i = 0; i < 10; i++)
{
  //do something
  
  //NOTE: the integer name does not need to be i, and the loop
  //doesn't need to start at 0. In addition, the 10 can be replaced
  //with any value. In this case, the loop will run 10 times.
  //Finally, the incrementation of i can be any value, in this case,
  //i increments by one. To increment by 2, for example, you would
  //use "i += 2", or "i = i+2"
}
Posted by: Guest on December-15-2019
20

Java for loop

int values[] = {1,2,3,4};
for(int i = 0; i < values.length; i++)
{
 	System.out.println(values[i]); 
}
Posted by: Guest on November-17-2019
12

java for

String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
for (String i : cars) {
  System.out.println(i);
}
Posted by: Guest on March-11-2020
16

for loop java

for (int i = 0; i < 5; i++) {
  System.out.println(i);
}
Posted by: Guest on December-10-2019
0

java loops

//This will do the look 4 times
for(int i = 0; i < 4; i++)
{
  ...
  }
Posted by: Guest on September-24-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language