1, Output 1 to 100 of these 100 numbers (respectively, for, while and do-while implementation).
public class test{public static void Main (string[] args) {System.out.println ("For loop output:");
for (int i=1;i<=100;i++) {System.out.print (i+ ""); } System.out.println ("\ n");
Change two lines of System.out.println ("While loop output:");
int i=1;
while (i<=100) {System.out.print (i+ "");
i++;
} System.out.println ("\ n");
System.out.println ("Do-while cycle output:");
int j=1;
do{System.out.print (j+ "");
j + +;
}while (j<=100);
} 2, 1 to 100 and (for, while, and Do-while respectively).
public class test{public static void Main (string[] args) {System.out.println ("For loop output:");
int sum1=0;
for (int i=1;i<=100;i++) {sum1+=i;
} System.out.println (SUM1);
System.out.println ("While loop output:");
int sum2=0;
int i=1;
while (i<=100) {sum2+=i;
i++;
} System.out.println (SUM2);
System.out.println ("Do-while cycle output:");
int sum3=0;
int j=1;
do{sum3+=j;
j + +; }while (J<=100);
System.out.println (SUM3);
} 3, get the product of 1 to 10 (with either loop implementation).
public class test{public static void Main (string[] args) {int sum=1;
for (int i=1;i<=8;i++) {sum*=i;
The product of System.out.println ("1 to 10 is:" +sum);
4, print out the following three types of 99 multiplication tables.
public class test{public static void Main (string[] args) {System.out.println ("First:");
for (int i=1;i<=9;i++) {for (int j=1;j<=i;j++) {System.out.print (i+ "*" +j+ "=" +i*j+ ");
if (i*j<10) System.out.print ("");
} System.out.println ();
} System.out.println ("Second:");
for (int i=1;i<=9;i++) {for (int j=9;j>=i;j--) {System.out.print (i+ "*" +j+ "=" +i*j+ ");
if (i*j<10) System.out.print ("");
} System.out.println ();
} System.out.println ("Third:"); for (int i=1;i<=9;i++) {for (int k=8;k>=i;k--) {//This loop is used to add a space System.out.print ("");
Add 7 spaces at a time for an expression of length} for (int j=1;j<=i;j++) {System.out.print (i+ "*" +j+ "=" +i*j+ "); if (i*j<10) System.out.print ("");
} System.out.println ();
} 5, print the following format pyramid, the number of rows of the pyramid can be arbitrarily specified.
public class test{public static void Main (string[] args) {int level=10;
for (int i=1;i<level;i++) {for (int k=i;k<level-1;k++) {//This loop is used to add a space System.out.print ("");
for (int j=1;j<= (2*i-1); j + +) {System.out.print ("*");
} System.out.println ();
} 6, Output 1 to 1000 can be divisible by 7, each row shows 10, and the output number is separated by a space.
public class test{public static void Main (string[] args) {int j=1;
for (int i=7;i<=1000;i+=7) {System.out.print (i+ "");
if (j%10==0) {//is used to determine whether the output is 10 times, the word is changed line System.out.println ();
} j + +; }
}
}