为什么b的值无法显示?

[复制链接]
查看11 | 回复1 | 2010-9-22 23:17:07 | 显示全部楼层 |阅读模式
import javax.swing.JOptionPane;
public class xunhuan6
{
public static void main(String[] args)
{ int a,b;int i=0;int c=0;int d=0;String out="";
String temp=JOptionPane.showInputDialog("Input a number:");
try{i=Integer.parseInt(temp); }
catch(Exception e)

{JOptionPane.showMessageDialog((null),"error,you should put int number","error",0);System.exit(0);}
if(i<=0)

{JOptionPane.showMessageDialog((null),"error,:i<=0!","error",0);

System.exit(0);}


if(0=3)

{a=1;b=1;

for(c=i;c<3;c--)

{



d=a+b;

a=b;

b=d;

}

out += i+"的斐波那契数是:"+d;

JOptionPane.showMessageDialog((null),out,"斐波那契数",1);

}
}
}
说错了是d的值

回复

使用道具 举报

千问 | 2010-9-22 23:17:07 | 显示全部楼层
应该在for循环里面i永远大于等于3c=i,c永远大于等于3那么条件c<3永远不成立for循环不执行d等于初始值0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行