(Java程序)麻烦dalao给每一行代码都加个注释。谢谢! 在线急等!!!
packagewzh;publicclassLhs003{publicstaticvoidmain(String[]args){inta=1,t=0;inti;for(i...
package wzh;
public class Lhs003 {
public static void main(String[] args) {
int a=1,t=0;
int i;
for(i=1;;i++) {
t=a;
a=a*i;
if(a/i!=t)
break;
}
System.out.println("Integer "+(i-1)+"!="+t);
long a1=1,t1=0;
long i1;
for(i1=1;;i1++) {
t1=a1;
a1=a1*i1;
if(a1/i1!=t1) {
break;
}
}
System.out.println("Long "+(i1-1)+"!="+t1);
byte a2=1,t2=0;
byte i2;
for(i2=1;;i2++) {
t2=a2;
a2=(byte) (a2*i2);
if(a2/i2!=t2) {
break;
}
}
System.out.println("Byte "+(i2-1)+"!="+t2);
short a3=1,t3=0;
short i3;
for(i3=1;;i3++) {
t3=a3;
a3=(short) (a3*i3);
if(a3/i3!=t3) {
break;
}
}
System.out.println("Short "+(i3-1)+"!="+t3);
double a4,t4=1,i4;
for (a4=1,i4 = 1; ; i4++) {
t4=a4;
a4=a4*i4;
if(a4>Double.MAX_VALUE) {
break;
}
}
System.out.println("Double "+(i4-1)+"!="+t4);
float a5,t5=1,i5;
for (a5=1,i5 = 1; ; i5++) {
t5=a5;
a5=a5*i5;
if(a5>Float.MAX_VALUE) {
break;
}
}
System.out.println("Float "+(i5-1)+"!="+t5);
/ar e='1';
char a6=1,t6=0;
char i6;
for(i6=1;;i6++) {
t6=a6;
a6=(char) (a6*i6);
if(a6/i6!=t6) {
break;
}
}
System.out.println("Character "+(i6-1)+"!="+(int)t6);
}
} 展开
public class Lhs003 {
public static void main(String[] args) {
int a=1,t=0;
int i;
for(i=1;;i++) {
t=a;
a=a*i;
if(a/i!=t)
break;
}
System.out.println("Integer "+(i-1)+"!="+t);
long a1=1,t1=0;
long i1;
for(i1=1;;i1++) {
t1=a1;
a1=a1*i1;
if(a1/i1!=t1) {
break;
}
}
System.out.println("Long "+(i1-1)+"!="+t1);
byte a2=1,t2=0;
byte i2;
for(i2=1;;i2++) {
t2=a2;
a2=(byte) (a2*i2);
if(a2/i2!=t2) {
break;
}
}
System.out.println("Byte "+(i2-1)+"!="+t2);
short a3=1,t3=0;
short i3;
for(i3=1;;i3++) {
t3=a3;
a3=(short) (a3*i3);
if(a3/i3!=t3) {
break;
}
}
System.out.println("Short "+(i3-1)+"!="+t3);
double a4,t4=1,i4;
for (a4=1,i4 = 1; ; i4++) {
t4=a4;
a4=a4*i4;
if(a4>Double.MAX_VALUE) {
break;
}
}
System.out.println("Double "+(i4-1)+"!="+t4);
float a5,t5=1,i5;
for (a5=1,i5 = 1; ; i5++) {
t5=a5;
a5=a5*i5;
if(a5>Float.MAX_VALUE) {
break;
}
}
System.out.println("Float "+(i5-1)+"!="+t5);
/ar e='1';
char a6=1,t6=0;
char i6;
for(i6=1;;i6++) {
t6=a6;
a6=(char) (a6*i6);
if(a6/i6!=t6) {
break;
}
}
System.out.println("Character "+(i6-1)+"!="+(int)t6);
}
} 展开
1个回答
2019-03-12
展开全部
package wzh; //引入包
public class Lhs003 { //类
public static void main(String[] args) { //主函数
int a=1,t=0;//定义两个int类型变量
int i;//同上
for(i=1;;i++) { //for循环,i递增,不设置上限
t=a; //a赋值给t
a=a*i; //计算并赋值
if(a/i!=t) //如果a/i !=t 则跳出循环
break;
}
System.out.println("Integer "+(i-1)+"!="+t); //后台输出
long a1=1,t1=0;//定义两个long类型变量
long i1;//定义变量
for(i1=1;;i1++) {//for循环,i1递增,不设置上限
t1=a1;//a赋值给t
a1=a1*i1;//计算并赋值
if(a1/i1!=t1) { 如果a/i !=t 则跳出循环
break;
}
}
System.out.println("Long "+(i1-1)+"!="+t1);//后台输出
//一下同上类似
byte a2=1,t2=0;
byte i2;
for(i2=1;;i2++) {
t2=a2;
a2=(byte) (a2*i2);
if(a2/i2!=t2) {
break;
}
}
System.out.println("Byte "+(i2-1)+"!="+t2);
short a3=1,t3=0;
short i3;
for(i3=1;;i3++) {
t3=a3;
a3=(short) (a3*i3);
if(a3/i3!=t3) {
break;
}
}
System.out.println("Short "+(i3-1)+"!="+t3);
double a4,t4=1,i4;
for (a4=1,i4 = 1; ; i4++) {
t4=a4;
a4=a4*i4;
if(a4>Double.MAX_VALUE) {
break;
}
}
System.out.println("Double "+(i4-1)+"!="+t4);
float a5,t5=1,i5;
for (a5=1,i5 = 1; ; i5++) {
t5=a5;
a5=a5*i5;
if(a5>Float.MAX_VALUE) {
break;
}
}
System.out.println("Float "+(i5-1)+"!="+t5);
/ar e='1';
char a6=1,t6=0; //定义字符型变量
char i6;//同上
for(i6=1;;i6++) {
t6=a6;
a6=(char) (a6*i6);//字符型计算取ASCI码比如 1 =49
if(a6/i6!=t6) {
break;
}
}
System.out.println("Character "+(i6-1)+"!="+(int)t6);
}
}
public class Lhs003 { //类
public static void main(String[] args) { //主函数
int a=1,t=0;//定义两个int类型变量
int i;//同上
for(i=1;;i++) { //for循环,i递增,不设置上限
t=a; //a赋值给t
a=a*i; //计算并赋值
if(a/i!=t) //如果a/i !=t 则跳出循环
break;
}
System.out.println("Integer "+(i-1)+"!="+t); //后台输出
long a1=1,t1=0;//定义两个long类型变量
long i1;//定义变量
for(i1=1;;i1++) {//for循环,i1递增,不设置上限
t1=a1;//a赋值给t
a1=a1*i1;//计算并赋值
if(a1/i1!=t1) { 如果a/i !=t 则跳出循环
break;
}
}
System.out.println("Long "+(i1-1)+"!="+t1);//后台输出
//一下同上类似
byte a2=1,t2=0;
byte i2;
for(i2=1;;i2++) {
t2=a2;
a2=(byte) (a2*i2);
if(a2/i2!=t2) {
break;
}
}
System.out.println("Byte "+(i2-1)+"!="+t2);
short a3=1,t3=0;
short i3;
for(i3=1;;i3++) {
t3=a3;
a3=(short) (a3*i3);
if(a3/i3!=t3) {
break;
}
}
System.out.println("Short "+(i3-1)+"!="+t3);
double a4,t4=1,i4;
for (a4=1,i4 = 1; ; i4++) {
t4=a4;
a4=a4*i4;
if(a4>Double.MAX_VALUE) {
break;
}
}
System.out.println("Double "+(i4-1)+"!="+t4);
float a5,t5=1,i5;
for (a5=1,i5 = 1; ; i5++) {
t5=a5;
a5=a5*i5;
if(a5>Float.MAX_VALUE) {
break;
}
}
System.out.println("Float "+(i5-1)+"!="+t5);
/ar e='1';
char a6=1,t6=0; //定义字符型变量
char i6;//同上
for(i6=1;;i6++) {
t6=a6;
a6=(char) (a6*i6);//字符型计算取ASCI码比如 1 =49
if(a6/i6!=t6) {
break;
}
}
System.out.println("Character "+(i6-1)+"!="+(int)t6);
}
}
追问
最后三个循环麻烦看一下
追答
//字符型计算取ASCI码比如 1 =49
其他的都是整形或者整数型
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询