问题出在哪里? [英] where is the problem?(fibonatcci).

查看:83
本文介绍了问题出在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题出在哪里?

where is the problem?

package fibonatchi;
class Main{
    public static void Main(String[]args){
System.out.printf("Wich Fibonacci Number do you want?");
//System.out.scanf("%d", &inp);
int fib1 = 1;
int fib2 = 0;
switch(fib)
 {
 case 0:
 System.out.printf(" Sorry, no result for f(0)");
   break;
 case 1:
 System.out.printf(" Fib(1) = 0");
   break;
 case 2:
   System.out.printf(" Fib(1) = 0");
   System.out.printf(" Fib(2) = 1");
   break;
 default:
   System.out.printf(" Fib(1) = 0");
   System.out.printf("Fib(2) = 1");
   for (int i=1; i<= fib -2; ++i)
    {
    fib = fib1 + fib2;
    fib2 = fib1;
    fib1 = fib;
      System.out.printf("Fib(%d) = %d", i + 2, fib);
    }
 }
}
}

推荐答案

您由此获得的输出是什么?

另外,本节有什么要求?

what output you are getting by this ?

Also what is the requirement of this section ?

mf_arian写道:
mf_arian wrote:

switch(fib)
{
案例0:
System.out.printf(对不起,f(0)没有结果");
休息;
情况1:
System.out.printf("Fib(1)= 0");
休息;
情况2:
System.out.printf("Fib(1)= 0");
System.out.printf("Fib(2)= 1");
休息;
默认值:

switch(fib)
{
case 0:
System.out.printf(" Sorry, no result for f(0)");
break;
case 1:
System.out.printf(" Fib(1) = 0");
break;
case 2:
System.out.printf(" Fib(1) = 0");
System.out.printf(" Fib(2) = 1");
break;
default:



实际上,您正在设置fib = 0,然后使用开关块,因此,每次程序进入开关时,它将打印Sorry,对于f(0)没有结果
然后退出.

所以问题出在开关上. :rose:



Actually you are setting fib = 0 and then using switch block, so every time the program enters the switch it will print Sorry, no result for f(0)
and exit.

So the issue is with the switch. :rose:


变量fib在任何地方都没有定义,因此该代码甚至无法编译.也许您应该检查一下算法.
Variable fib is not defined anywhere so this code does not even compile. Perhaps you should review your algorithm.


这篇关于问题出在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆