1.
使用do-while实现:输出摄氏温度与华氏温度的对照表,要求它从摄氏温度0度到250度,每隔20度为一项,对照表中的条目不超过10条。
转换关系:华氏温度 = 摄氏温度 * 9 / 5.0 + 32
double f=0.0;//表示华氏温度 double c=0.0;//表示摄氏温度 int num=0; do { System.out.print("摄氏温度"+"\t"+"华氏温度"); System.out.println(); System.out.print(c+"\t"); f=c*9/5.0+32; c=c+20; num++; System.out.println(f); } while (num<=10&&c<=250);
2 计算100以类的偶数和
int a = 1; int add = 0; while (a <= 100) { if (a % 2 == 0) { add = add + a; a++; } a++; } System.out.println("偶数和是:" + add);