Today I will write about iterative processing of java.
A process that repeats an instruction given a certain instruction
When the execution result is output like this
[1] [2] [3] [4] [5]
Normally
Normal processing
public class PrintFiveStars { |
public static void main (String[] args){ |
System.out.println("[1]");
System.out.println("[2]");
System.out.println("[3]");
System.out.println("[4]");
System.out.println("[5]");
}
}
When using iterative syntax It only takes about 5 lines. If you apply this, 100 or 1000 lines You can do the processing just by editing.
Iterative processing
public class Print100Stars {
public static void main (String[] args) {
int sum = 0;
for (int i = 1; i <= 5; i++){
sum += 1;
System.out.println(sum);
}
}
}
Recommended Posts