作业1:循环输出“好好学习天天向上”
作业代码如下:
public class 循环输出好好学习天天向上 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//定义一个变量
int nh = 1;
//创建一个循环
while(nh < 100){
//输出语句
System.out.println("你好"+nh);
System.out.println("好好学习天天向上"+nh);
nh++;
}
}
}
代码运行效果如下:
作业2:循环输出1到10
作业代码如下:
public class 输出1到10 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//用do...while循环结构输出1到10
int sc = 1;
//do=干什么
do{
System.out.println(sc);
sc++;
}
//当什么等于什么条件
while(sc <= 10);
}
}
代码运行效果如下:
作业3:循环输出1到10
作业代码如下:
public class 循环输出1到100 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//用do...while循环结构输出1到10
int sc = 1;
//do=干什么
do{
System.out.println(sc);
sc++;
}
//当sc小于等于100条件
while(sc <= 100);
}
}
作业代码运行如下:
作业4:循环输出星号
public class 循环输出星号 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int a = 1;
while(a<=5){
System.out.println("*****");
a++;
}
}
}
作业代码运行如下: