JAVA第六次作业

1.

public class Hestia {
    public static void main(String[] args) {

    int temp = 0; // 定义一个记录次数的变量

    for (int i = 1; i <= 100; i++) { // 利用 for 循环遍历 1-100 的数

        if (i % 3 == 0) { // 设置条件,能被 3 整除则输出

            System.out.print(i + " "); // 输出

            temp++; // 迭代输出次数

        }

        if (temp == 5) { // 如果输出五次就退出循环

            break;

        }

    }

}
}
public class Hestia {
    public static void main(String[] args) {
        for(int i=3,j=1;i<=100;i=i+3,j++){
            System.out.print(i+" ");
            if(j==5){return ;}
        }
    }
}
public class hestia1 {
    public static void main(String[] args) {
        int i=3,h=0;
        while (h<5){
            System.out.print(i+" ");
            i+=3;
            h++;
        }
    }
}
public class hestia1 {
    public static void main(String[] args) {
        int i=3,h=0;
        while (true){
            System.out.print(i+" ");
            i+=3;
            h++;
            if(h==5){break;}
        }
    }
}
public class hestia1 {
    public static void main(String[] args) {
        for(int i=3,j=1;i<=100;i=i+3,j++){
            System.out.print(i+" ");
            if(j==5){System.exit (0);}
        }
    }
}
public class hestia1 {
    public static void main(String[] args) {
        for(int i=3,j=1;i<=100;i=i+3,j++){
            if(j>5){continue;}
            System.out.print(i+" ");
        }
    }
}

2.

public class Book {
    public String name;
    public int pages;
    public void setName(String name) {
        this.name = name;
    }
    public void setPages(int pages) {
        this.pages = pages;
    }

    public String getName(){
        return name;
    }
    public int getPages() {
        return pages;
    }

    public void display(String h_name,int h_papgs){
        setName(h_name);
        setPages(h_papgs);
        System.out.println("书名为:"+getName());
        System.out.print("页数为:"+getPages());
    }

    public static void main(String[] args){
        Book hestia_book =new Book();
        hestia_book.display("高等元素论",1314);
    }
}

将悲伤的事对半分吧,将快乐的事拼凑成双吧