View Code of Problem 23

import java.util.Scanner;

public class Main8 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            Integer get = Integer.valueOf(scanner.nextLine());
            if (get == 0) {
                break;
            }
            int n1 = 0;
            int n2 = 1;
            for (int i = 1; i <= get; i++) {
                n1 += n2;//grow up to adult
                n2 = n1 - n2;
            }
            System.out.println(n1 + n2);
        }
    }
}
/*
Main.java:3: error: class Main8 is public, should be declared in a file named Main8.java
public class Main8 {
       ^
1 error
*/

Double click to view unformatted code.


Back to problem 23