Title: Classical questions: There are a pair of rabbits, from the 3rd month after birth a pair of rabbits each month, the rabbit long to the third month after the birth of a pair of rabbits, if the rabbit is not dead, ask each month the total number of rabbits?
1. Program analysis: The law of Rabbits for the series 1,1,2,3,5,8,13,21 ....
Importjava.io.BufferedReader;Importjava.io.IOException;Importjava.io.InputStreamReader; public classTest6 { public Static voidMain (string[] Args)throwsnumberformatexception, ioexception{System.out.println ("please Enter the number of months:"); BufferedReader BR=NewBufferedReader (NewInputStreamReader (system.in)); intI=Integer.parseint (br.readline ()); ints=value (i); System.out.println ("the number of rabbits in the month is:" +s); } Private Static intValueintI) { intNum=1; if(i<=2){ returnNum=1; }Else{ returnValue (i-2) +value (i-1); } } }
Java interview one question per day 6