for循化
package Test;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int i = s.nextInt();
int a=1;
int sum=1;
for(a=1;a<=i;a++){
System.out.print(a);
if(a!=i){
System.out.print("*");
}
sum=sum*a;
}
System.out.print("=");
System.out.print(sum);
}
}
while循环
package Test;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int i = s.nextInt();
int a=1;
int sum=1;
while(a<=i){
System.out.print(a);
if(a!=i){
System.out.print("*");
}
sum=sum*a;
a++;
}
System.out.print("=");
System.out.print(sum);
}
}
do-while循环
package Test;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int i = s.nextInt();
int a=1;
int sum=1;
do{
System.out.print(a);
if(a!=i){
System.out.print("*");
}
sum=sum*a;
a++;
}while(a<=i);
System.out.print("=");
System.out.print(sum);
}
}