The processes called loop processing and iterative processing are summarized. The following three are prepared in Java.
--for statement --while statement --do statement (do while)
-** for ( Initial value setting </ font>; Continuation condition </ font>; Value manipulation </ font> font>) { Processing </ font>} **
-** while ( condition </ font>) { processing </ font>} **
-** do { Processing </ font>} while ( Condition </ font>); **
A program that inputs numbers and displays only the number *
import java.util.Scanner;
class PutKome {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
System.out.print("How many rice do you want to display:");
int n = stdIn.nextInt();
for (int i = 0; i < n; i++) {
System.out.print('*');
}
System.out.println();
}
}
【result】
What pieces*Do you want to display: 5
*****
Recommended Posts