1.打印9*9乘法表
public class Test {
public static void main(String[] args){
for(int i=1;i<=9;i++){
for(int j=1;j<=i;j++){
System.out.print(j+"*"+i+"="+i*j+"\t");
}
System.out.println();
}
}
}
2.从0~100随机输出一个数
mport java.util.Random;
public class Test {
public static void main(String[] args){
Random e= new Random();
int a=e.nextInt(101);
System.out.println(a);
}
}
3.纸张厚度为8cm,求折叠多少次大于珠穆朗玛峰的高度
public class Test {
public static void main(String[] args){
int count=0;
double paper=0.08;
while(1==1){
paper=paper*2;
count++;
System.out.println("折叠"+count+"次,高度为"+paper);
if(paper>=8848000){
break;
}
}
}
}
4.数组的逆序
public class Test {
public static void main(String[] args){
int[]a={1,2,3,4};
System.out.println("数组的逆序为:");
for(int i=a.length-1;i>=0;i--){
System.out.print(a[i]+" ");
}
}
}
5.遍历数组
public class Test {
public static void main(String[] args){
double[]d={3.14,6.66,7.89,2.68,0.5};
for(double x:d){
System.out.println("当前循环取出值为:"+x);
}
}
}
6.异常处理
import java.util.Scanner;
public class Test {
public static void main(String[] args){
Scanner input=new Scanner(System.in);
System.out.println("请输入a,b:");
int a=input.nextInt();
int b=input.nextInt();
int c=a/b;
System.out.println(c);
if(b==0){
System.out.println("输出错误");
try{
throw new Exception("异常,请重新输入");
}catch(Exception e){
e.printStackTrace();
}finally{
System.out.println("测试完毕!");
}
}
}
}