Package Practicego;import java.util.scanner;/* 3. The number of times the loop executes is determined by the value entered, and the loop variable starts from 1 by default */public class Cto {public static void main (S Tring[] args) {Scanner sc = new Scanner (System. in); System.out.println ("Please enter the number of cycles:"), int time = Sc.nextint (), for (int i=1; i<=time; i++) {System.out.println ("+i+");}}}
Test:
Please enter the number of cycles: 5 1th 2nd 3rd times 4th 5th Times
Please enter the number of cycles: 100 The 1th 3rd time 4th Times 5th Times 6th Times 7th Times 8th Times 9th Times 10th Times 11th Times 12th Times 13th Times 14th Times 15th Times 16th Times 17th Times 18th times 19th Times 20th Times 21st Times 22nd Times 23rd Time 24th Times 25th Times 26th 31st Time 32nd 33rd Times 34th Times 35th Times 36th Times 37th Times 38th Times 39th Times 40th Times 41st Times 42nd Times 43rd Times 44th Times 45th Times 46th Times 47th Times 48th Times 49th Times 50th Times 51st Times 52nd Times 53rd Times 54th Times 55th Times 56th Times 57th Times 61st 62nd 63rd Times 64th Times 65th Times 66th Times 67th Times 68th Times 69th Times 70th Times 71st Times 72nd Times 73rd Times 74th Times 75th Times 76th Times 77th Times 78th Times 79th Times 80th Times 81st Times 82nd Times 83rd Times 84th Times first 85th times 86th Times 91 92nd Times 93rd 94th 95th Times 96th Times 97th Times 98th Times 99th Times 100th times
Java Loop Exercise: The number of times the loop executes is determined by the value entered, and the loop variable defaults from 1