写一个JAVA程序 输出从1到100的整数

public class 5

用for、while、do-while 3种语句做

老师作业~

第1个回答  2009-09-27
public class T5{
pubic static void main(String[] args){

for(int i=1;i<=100;i++)
System.out.println(i);

int i=1;
while(i<=100){
System.out.println(i);
i++;
}
i=1;
do{
System.out.println(i);
i++;
}while(i<=100)

}

}
第2个回答  2009-09-27
public class One2OnehundredNumber
{
//for statement
public void forStatement(){
for (int i = 1; i <= 100 ; i++)
{
System.out.print(i + " ");
}
}

//while statement
public void whileStatement(){
int i = 1;
while (i <= 100)
{
System.out.println(i + " ");
i++;
}
}

//do while statement
public void dowhileStatement(){
do
{
System.out.println(i + " ");
i++;
}
while (i <= 100);
}

//测试
public static void main(String[] args)
{
One2OnehundredNumber oon = new One2OnehundredNumber();
oon.forStatement();
oon.whileStatement();
oon.dowhileStatement();
}
}
第3个回答  推荐于2017-09-21
for (int a = 1; a<=100; a++)
{
system.out.println(a);
}

/////////

int a =1;
while (a <=100)
{
system.out.println(a);
a++;
}

/////////

int a = 1;
do
{
system.out.println(a);
a++;
}
while (a<=100)

不大记得JAVA的屏幕输出是不是这样~呵呵 很久没用了 我是用C++的 看到就顺手帮你写了几个本回答被提问者采纳
相似回答