(5)
import java.util.Scanner;
public class Work10{
public static void main(String [] args){
Scanner sc=new Scanner(System.in);
System.out.print(“请输入层数”);
int layer=sc.nextInt();
for(int i=1;i<=layer;i++){
if (i<=(layer/2)){
int spaceNum=(layer/2)-i+1;
for(int j=1;j<=spaceNum;j++){
System.out.print(" “);
}
int starNum=2i-1;
for(int j=1;j<=starNum;j++){
if(j1||jstarNum){
System.out.print("”);
}else{
System.out.print(" ");
}
}
}
if(i>layer/2){
int spaceNum2=(i-((layer/2+1)));
for(int j=1;j<=spaceNum2;j++){
System.out.print(" ");
}
int starNum2=(2*(layer-i)+1);
for(int j=1;j<=starNum2;j++){
if (j==1||j==starNum2){
System.out.print("*");
}else{
System.out.print(" ");
}
}
}
System.out.println(" ");
}
}
}
(6)
import java.util.Scanner;
public class Work11{
public static void main(String [] args){
Scanner sc=new Scanner(System.in);
System.out.print(“请输入层数”);
int layer=sc.nextInt();
for(int i=1;i<=layer;i++){
if (i<=(layer/2)){
int spaceNum=(layer/2)-i+1;
for(int j=1;j<=spaceNum;j++){
System.out.print(" “);
}
int starNum=2i-1;
for(int j=1;j<=starNum;j++){
if(j1||jstarNum||j==starNum/2+1){
System.out.print("”);
}else{
System.out.print(" ");
}
}
}
if(i>layer/2){
int spaceNum2=(i-((layer/2+1)));
for(int j=1;j<=spaceNum2;j++){
System.out.print(" ");
}
int starNum2=(2*(layer-i)+1);
for(int j=1;j<=starNum2;j++){
if (j==1||j==starNum2){
System.out.print("*");
}else{
System.out.print(" ");
}
}
}
System.out.println(" ");
}
}
8、九九乘法口诀表
public class Work13{
public static void main (String [] args){
for(int i=1;i<10;i++){
for(int j=1;j<=i;j++){
System.out.print(i+""+j+"="+(ij)+" “);
}
System.out.println(” ");
}
}
}