展开全部
第一个:62616964757a686964616fe59b9ee7ad9431333365653262public class App1 {
static int fib(int n) {
if (n == 0 || n == 1) {
return 1;
}
return fib(n - 1) + fib(n - 2);
}
public static void main(String[] args) {
for (int i = 20; i <= 30; i++) {
System.out.print(Integer.toString(fib(i)) + " ");
}
}
}
第二个:public class App2 {
public static void main(String[] args) {
for (int i = 0; i <= 20; i++) {
for (int j = 0; j <= 33; j++) {
for (int k = 0; k <= 100; k++) {
if (i * 5 + j * 3 + k / 3 == 100 && i + j + k == 100 && k % 3 == 0)
System.out.println("公鸡:" + i + " 母鸡:" + j + " 小鸡:" + k);
}
}
}
}
}
第三个:import java.io.FileWriter;
import java.io.IOException;
import java.util.*;
class Book {
private String title;
private String author;
private int pageCount;
public Book() {
this("", "", 0);
}
public Book(String title, String author, int pageCount) {
this.title = title;
this.author = author;
this.pageCount = pageCount;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public int getPageCount() {
return pageCount;
}
public void setPageCount(int pageCount) {
this.pageCount = pageCount;
}
public void print() {
System.out.println(title + "\t" + author + "\t" + pageCount);
}
public String getBookInfo() {
return "书名:" + title + ",作者:" + author + ",页数:" + pageCount;
}
}
public class LibraryCollectionTest {
private static Scanner scanner = new Scanner(System.in);
private static List books = new ArrayList();
private static Book input() {
Book book = new Book();
System.out.print("请输入书名:");
book.setTitle(scanner.next());
System.out.print("请输入作者:");
book.setAuthor(scanner.next());
System.out.print("请输入页数:");
book.setPageCount(scanner.nextInt());
return book;
}
public static void main(String[] args) throws IOException {
while (true) {
System.out.print("是否添加图书?(true/false)");
if (!scanner.nextBoolean()) {
break;
}
Book book = input();
books.add(book);
}
FileWriter writer = new FileWriter("books.txt");
for (Book book : books) {
writer.write(book.getBookInfo() + System.lineSeparator());
}
writer.close();
}
}