我在尝试将斐波那契序列重新创建为Java程序时遇到了一些问题,我相信它可能与(FiboNacci)方法有关,任何帮助将不胜感激!
import java.util.*;
public class LabWeek2 {
public static void main(String[] args) {
System.out.println("----------------------");
System.out.println("Welcome to Fibonaccis:");
System.out.println("----------------------");
//import the scanner
Scanner in = new Scanner (System.in);
/
System.out.println("To start, please enter the
maximum number:");
/////
int userChoice = in.nextInt();
/// The conditions to the Fibonacci Sequence
System.out.println("The sum of all even fibonaccis
before " + userChoice + " is: " );
if (userChoice == 0){
System.out.println(0);
}
if (userChoice == 1) {
System.out.println(1);
}
if (userChoice > 1){
FiboNacci(userChoice);
}
}
public static void FiboNacci (int x){
for (int i = 2; i < x; i++){
int fn_1 = x - 1;
int fn_2 = x - 2;
x = fn_1 + fn_2;
}
System.out.println(x);
}
}
答案 0 :(得分:0)
感谢所有提供帮助的人,我最终对方法进行了一些更改,使它起作用。
grep("[^su|a][i][t]$", words, value =T )