- 循环输出
*
* *
* * *
* * * *
| |
| |
public class Tree{
public static void main (String [] args){
int line = 4;
int i;
int j;
for(i=0;i<line;i++){
for(j=0;j<line-i;j++){
System.out.print(" “);
}
for(j = 0;j<i+1;j++){
System.out.print(”* “);
}
System.out.println();
}
for(i=0;i<2;i++){
for(j=0;j<line-1;j++){
System.out.print(” “);
}
for(j = 0;j<2;j++){
System.out.print(”| ");
}
System.out.println();
}
}
} - 输出 99乘法口诀表
11=1
12=2 2*2=4
…
public class Chengfabiao{
public static void main(String[] args){
int i;
int j;
for(i=1;i<10;i++){
for(j=1;j<=i;j++){
System.out.print(j+""+i+"="+ij+"\t");
}
System.out.println();
}
}
}
- 鸡兔同笼(输入头和脚的数量,输出鸡和兔的个数)
import java.util.;
public class Jitu{
public static void main(String[] args){
Scanner scanner =new Scanner (System.in);
int heads=scanner.nextInt();
int feet=scanner.nextInt();
int c=(feet-2heads)/2;
int t=heads-(feet-2*heads)/2;
if (feet%2!=0||c<0||t<0){
System.out.println(“0”);
}else{
System.out.println(“c=”+c);
System.out.println(“t=”+t);
}
}
}