將費氏數列輸出至一long 陣列
其中f[0]=1, f[1]=2, f[n]=f[n-1]+f[n-2] (n>=2)
herrDeng網內搜尋
自訂搜尋
Ads
2011年10月6日 星期四
訂閱:
張貼留言 (Atom)
熱門文章
-
教育部為提昇全民資安素養與電腦防護能力,本部於101年9月5日至11月5日舉辦「全民資安素養自我評量」活動,請在活動期間內踴躍上網檢測資訊安全素養認知程度,並有機會參與抽獎,詳情請參閱活動網站(網址: https://isafe.moe.edu.tw/event
-
先說明一下這是後知後覺的解答,所謂後知就是股票價格已知存在陣列(清單),當然就要用迴圈練習,雙迴圈暴力解需時O(n**2),當然不用,採python單一迴圈解答「最佳股票的買賣時機#LeetCode 121 Best Time to Buy and Sell Stock」,解...
-
url="https://www.twse.com.tw/exchangeReport/STOCK_DAY?response=json&date=20220330&stockNo=2330"
-
你會用C的算子sizeof?
-
Python CPP heap priority queue速解L eetcode 2530. Maximal Score After Applying K Operations heap/priority queue是重要的資料結構,無論是C++的std::priority_q...
-
C++ DP動態規劃解Leetcode 937 Maximum Number of Points with Cost 有些標示medium要比標示hard的問題還要難,Leetcode 1937. Maximum Number of Points with Cost,DP動態規...
68 則留言:
public class A {
public static void main(String[] args)
{
long[] f = new long[100] ;
f[0] = 1;
f[1] = 2;
for(int i = 2; i < f.length; i++)
{f[i] = f[i-1] + f[i-2];}
for(int i = 0; i < f.length; i++)
{System.out.print(" "+f[i]);
System.out.println();}
}
}
package p1;
public class a1 {
public static void main(String[] args) {
{
long[] f = new long[100] ;
f[0] = 1; f[1] = 2;
for(int i = 2; i < f.length; i++)
{f[i] = f[i-1] + f[i-2];}
for(int i = 0; i < f.length; i++)
{System.out.print(" "+f[i]);
System.out.println();} }
}
}
package P1;
public class A1
{
public static void main(String[] args)
{
long[] f = new long[100] ;
f[0] = 1;
f[1] = 2;
for(int i = 2; i < f.length; i++)
{f[i] = f[i-1] + f[i-2];}
for(int i = 0; i < f.length; i++)
{System.out.print(" "+f[i]);
System.out.println();}
}
}
package P1;
public class A1
{
public static void main(String[] args)
{
long[] f = new long[100] ;
f[0] = 1;
f[1] = 2;
for(int i = 2; i < f.length; i++)
{f[i] = f[i-1] + f[i-2];}
for(int i = 0; i < f.length; i++)
{System.out.print(" "+f[i]);
System.out.println();}
}
}
package B9933057;
public class B9933057 {
public static void main(String[] args) {
long[] f = new long[100] ;
f[0] = 1;
f[1] = 2;
for(int i = 2; i < f.length; i++)
{f[i] = f[i-1] + f[i-2];}
for(int i = 0; i < f.length; i++)
{System.out.print(" "+f[i]);
System.out.println();}
}
}
package P1;
public class A1
{
public static void main(String[] args)
{
long[] f = new long[100] ;
f[0] = 1;
f[1] = 2;
for(int i = 2; i < f.length; i++)
{f[i] = f[i-1] + f[i-2];}
for(int i = 0; i < f.length; i++)
{System.out.print(" "+f[i]);
System.out.println();}
}
}
package P1;
public class A1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
{
long[] f = new long[100] ;
f[0] = 1;
f[1] = 2;
for(int i = 2; i < f.length; i++)
{f[i] = f[i-1] + f[i-2];}
for(int i = 0; i < f.length; i++)
{System.out.print(" "+f[i]);
System.out.println();}
}
}
}
package P1;
public class A1
{
public static void main(String[] args)
{
long[] f = new long[100] ;
f[0] = 1;
f[1] = 2;
for(int i = 2; i < f.length; i++)
{f[i] = f[i-1] + f[i-2];}
for(int i = 0; i < f.length; i++)
{System.out.print(" "+f[i]);
System.out.println();}
}
}
package P1;
public class A1
{
public static void main(String[] args)
{
long[] f = new long[100] ;
f[0] = 1;
f[1] = 2;
for(int i = 2; i < f.length; i++)
{f[i] = f[i-1] + f[i-2];}
for(int i = 0; i < f.length; i++)
{System.out.print(" "+f[i]);
System.out.println();}
}
}
package P1;
public class A1
{
public static void main(String[] args)
{
long[] f = new long[100] ;
f[0] = 1;
f[1] = 2;
for(int i = 2; i < f.length; i++)
{f[i] = f[i-1] + f[i-2];}
for(int i = 0; i < f.length; i++)
{System.out.print(" "+f[i]);
System.out.println();}
}
}
package P1;
public class A1
{
public static void main(String[] args)
{
long[] f = new long[100] ;
f[0] = 1;
f[1] = 2;
for(int i = 2; i < f.length; i++)
{f[i] = f[i-1] + f[i-2];}
for(int i = 0; i < f.length; i++)
{System.out.print(" "+f[i]);
System.out.println();}
}
}
public class B1 {
public static void main(String[] args) {
long[] f=new long[100];
f[0]=1;
f[1]=2;
for(int i=2; i<f.length;i++)
{
f[i]=(f[i-1]+f[i-2]);
System.out.println("f["+i+"]="+f[i]);
}
}
}
public class b9933014 {
public static void main(String[] args) {
long[] f = new long[100] ;
f[0] = 1;
f[1] = 2;
for(int i=2;i<f.length;i++)
{
f[i] = f[i-1] + f[i-2];
}
for(int i=0;i<f.length;i++)
{
System.out.print(" "+f[i]);
System.out.println();
}
}
}
package A2;
public class A1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
long[] f = new long[100] ;
f[0] = 1;
f[1] = 2;
for(int i = 2; i < f.length; i++)
{
f[i] = f[i-1] + f[i-2];
}
for(int i = 0; i < f.length; i++)
{
System.out.print(" "+f[i]);
System.out.println();
}
}
}
package P1;
public class B9933052A {
public static void main(String[] args) {
long [] f =new long[100];
f[0]=1;
f[1]=2;
for (int i=2;i<f.length;i++)
{
f[i]=f[i-1]+f[i-2];
System.out.println("f["+i+"]="+f[i]);
}
}
}
最大陣列值到f[90];
package P1;
public class A1
{
public static void main(String[] args)
{
long[] f = new long[100] ;
f[0] = 1;
f[1] = 2;
for(int i = 2; i < f.length; i++)
{f[i] = f[i-1] + f[i-2];}
for(int i = 0; i < f.length; i++)
{System.out.print(" "+f[i]);
System.out.println();}
}
public class B1 {
public static void main(String[] args) {
long[] f=new long[100];
f[0]=1;
f[1]=2;
for(int i=2; i<f.length;i++)
{
f[i]=(f[i-1]+f[i-2]);
System.out.println("f["+i+"]="+f[i]);
}
}
}
最大陣列值到f[90]
public class A1
{
public static void main(String[] args)
{
long[] f = new long[100] ;
f[0] = 1;
f[1] = 2;
for(int i = 2; i < f.length; i++)
{f[i] = f[i-1] + f[i-2];}
for(int i = 0; i < f.length; i++)
{System.out.print(" "+f[i]);
System.out.println();}
}
}
package A2;
public class A1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
long[] f = new long[100] ;
f[0] = 1;
f[1] = 2;
for(int i = 2; i < f.length; i++)
{
f[i] = f[i-1] + f[i-2];
}
for(int i = 0; i < f.length; i++)
{
System.out.print(" "+f[i]);
System.out.println();
}
}
}
package b9933024;
public class a1
{
public static void main(String[] args)
{
long[] f = new long[100] ;
f[0] = 1;
f[1] = 2;
for(int i = 2; i < f.length; i++)
{f[i] = f[i-1] + f[i-2];}
for(int i = 0; i < f.length; i++)
{System.out.print(" "+f[i]);
System.out.println();}
}
}
package p1;
public class a {
public static void main(String[] args) {
long[] f = new long[100] ;
f[0] = 1;
f[1] = 2;
for(int i = 2; i < f.length; i++)
{f[i] = f[i-1] + f[i-2];}
for(int i = 0; i < f.length; i++)
{System.out.print(" "+f[i]);
System.out.println();} }
}
package B9933040;public class B9933040 { public static void main(String[] args) { long[] f = new long[100] ; f[0] = 1; f[1] = 2; for(int i = 2; i < f.length; i++) {f[i] = f[i-1] + f[i-2];} for(int i = 0; i < f.length; i++) {System.out.print(" "+f[i]); System.out.println();} } }
package pack1;
import java.io.*;
public class A1 {
public static void main(String[] args) {
long[] f = new long[100] ;
f[0] = 1;
f[1] = 2;
for(int i = 2; i < f.length; i++)
{f[i] = f[i-1] + f[i-2];}
for(int i = 0; i < f.length; i++)
{System.out.print(" "+f[i]);
System.out.println();}
}
}
package B9933004;public class B9933004 { public static void main(String[] args) { long[] f = new long[100] ; f[0] = 1; f[1] = 2; for(int i = 2; i < f.length; i++) {f[i] = f[i-1] + f[i-2];} for(int i = 0; i < f.length; i++) {System.out.print(" "+f[i]); System.out.println();} } }
package pack1;
import java.io.*;
public class test1 {
public static void main(String[] args) {
long [] fib =new long[100];
fib[0]=1;
fib[1]=2;
for(int i=2;
i<fib.length;i++)
fib[i]=fib[i-1]+fib[i-2];
for(int i=0;
i<fib.length;i++)
System.out.println(i+"->"+fib[i]+" " );
System.out.println();
}
}
package B9933046;public class B9933046 { public static void main(String[] args) { long[] f = new long[100] ; f[0] = 1; f[1] = 2; for(int i = 2; i < f.length; i++) {f[i] = f[i-1] + f[i-2];} for(int i = 0; i < f.length; i++) {System.out.print(" "+f[i]); System.out.println();} } }
package pack1;
import java.io.*;
public class test1 {
public static void main(String[] args) {
long [] fib =new long[100];
fib[0]=1;
fib[1]=2;
for(int i=2;
i<fib.length;i++)
fib[i]=fib[i-1]+fib[i-2];
for(int i=0;
i<fib.length;i++)
System.out.println(i+"->"+fib[i]+" " );
System.out.println();
}
}
public class b9933011 {
public static void main(String[] args) {
long []f=new long[100];
f[0]=1;
f[1]=2;
for(int i=2;i<f.length;i++)
{
f[i]=(f[i-1]+f[i-2]);
System.out.println("f["+i+"]="+f[i]);
}
}
}
最大陣列數值 90
public class B41 {
public static void main(String[] args) {
long[] f=new long[100];
f[0]=1;
f[1]=2;
for(int i=2;i<f.length;i++)
{
f[i]=(f[i-1]+f[i-2]);
System.out.println("f["+i+"]="+f[i]);
}
}
}
最大陣列數值是90
package p1;
public class b1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
long[] f=new long[100];
f[0]=1;
f[1]=2;
for(int i=2; i<f.length; i++)
f[i]= f[i-1]+f[i-2];
for(int i=0; i<f.length; i++)
System.out.println(i+"->"+f[i]+" ");
System.out.println();
}
}
最大索引值=90
public static void main(String[] args)
{
long[] f = new long[100];
f[0] = 0;
f[1] = 1;
for(int i = 2; i < f.length; i++)
f[i] = f[i-1] + f[i-2];
for(long number : f)
System.out.print(number + " ");
System.out.println();
}
package pack1;
public class A1 {
public static void main(String[] args) {
long[] f=new long[100];
f[0]=1;
f[1]=2;
for(int i=2; i<f.length;i++)
{
f[i]=f[i-1]+f[i-2];
System.out.println("f["+i+"]="+f[i]);
}
}
}
最大值f[90];
long [] f=new long[100];
f[0]=1;
f[1]=2;
for(int i = 2; i <f.length; i++)
f[i] = f[i-1] + f[i-2];
for(int i = 0; i < f.length; i++)
System.out.print(f[i] + " ");
System.out.println();
package pack;
public class pack {
public static void main(String[] args) {
long [] f=new long[100];
f[0]=1;
f[1]=2;
for(int i=2; i<f.length; i++)
{
f[i]=f[i-1]+f[i-2];
System.out.println("f["+i+"]="+f[i]);
}
}
}
最大值f[90];
package pack1;
import java.io.*;
public class test1 {
public static void main(String[] args) {
long [] fib =new long[100];
fib[0]=1;
fib[1]=2;
for(int i=2;
i<fib.length;i++)
fib[i]=fib[i-1]+fib[i-2];
for(int i=0;
i<fib.length;i++)
System.out.println(i+"->"+fib[i]+" " );
System.out.println();
}
}
最大索引值=90
package pack1;
public class B1 {
public static void main(String[] args) {
long[] fib =new long[100];
fib[0] = 1;
fib[1] = 2;
for(int i = 2;
i < fib.length; i++)
fib[i] = fib[i-1] + fib[i-2];
for(int i = 0;
i < fib.length; i++)
System.out.println(i+"->"+fib[i] + " ");
System.out.println();
}
}
最大索引直:90
package pack1;
public class A1 {
public static void main(String[] args) {
long[] fib=new long[100];
fib[0]=1;
fib[1]=2;
for(int i=2;
i <fib.length;i++)
fib[i]=fib[i-1]+fib[i-2];
for(int i=0;
i <fib.length;i++)
System.out.println(i+"->"+fib[i]+" ");
System.out.println();
}
}
最大索引值=90
package p1;
public class p1 {
public static void main(String[] args) {
long []fib=new long [91];
fib[0]=1;
fib[1]=2;
for(int i=2; i<fib.length; i++ )
fib[i]=fib[i-1]+fib[i-2];
for(int i=0; i<fib.length; i++ )
System.out.println(i+"->"+fib[i]+" ");
System.out.println();
}
}
最大索引值:90
package p1;
public class b2 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
long []fib=new long [91];
fib[0]=1;
fib[1]=2;
for(int i=2; i<fib.length; i++)
fib[i]=fib[i-1]+fib[i-2];
for(int i=0; i<fib.length; i++)
System.out.println(i+"->"+fib[i]+" ");
System.out.println();
}
}
最大索引值90
package a1;
public class a1 {
public static void main(String[] args) {
long[]f=new long[100];
f[0]=1;
f[1]=2;
for(int i = 2; i < f.length; i++)
f[i] = f[i-1] + f[i-2];
for(int i = 0; i < f.length; i++)
System.out.println("f"+i+"="+" "+f[i]);
System.out.println();
}
}
答案最大是F90
package p4;
public class M1 {
public static void main(String[] args) {
long f[]=new long[100];
f[0]=1;
f[1]=2;
for ( int i=2;i<f.length;i++)
f[i]=f[i-1]+f[i-2];
for (int i=0;i<f.length;i++)
System.out.println(i+"->"+f[i]+" ");
System.out.println();
}
}
package p1;
public class B1 {
public static void main(String []args){
long f[]=new long [100];
f[0]=1;
f[1]=2;
for ( int i=2;i<f.length;i++)
f[i]=f[i-1]+f[i-2];
for (int i=0;i<f.length;i++)
System.out.println(i+"->"+f[i]+" ");
System.out.println();
}
}
public class P1 {
public static void main(String[] args) {
long[]f=new long [100];
f[0]=1;
f[1]=2;
for(int i=2;i<f.length;i++)
f[i]=f[i-1]+f[i-2];
for(int i=0; i<f.length;i++)
System.out.println(i+" "+f[i]+" ");
System.out.println();
}
}
最大值:90
public static void main(String[] args) {
long[] f = new long[100] ;
f[0] = 1;
f[1] = 2;
for(int i = 2; i < f.length; i++)
{f[i] = f[i-1] + f[i-2];}
for(int i = 0; i < f.length; i++)
{System.out.print("f"+i+" "+f[i]);
System.out.println();}
}
}
最大值在90
package pack;
public class pack {
public static void main(String[]args) {
long [] f=new long[100];
f[0]=1;
f[1]=2;
for(int i=2; i<f.length; i++)
{
f[i]=f[i-1]+f[i-2];
System.out.println("f["+i+"]="+f[i]);
}
}
}
package p1;
public class p1 {
public static void main(String[] args) {
long []fib=new long [91];
fib[0]=1;
fib[1]=2;
for(int i=2; i<fib.length; i++ )
fib[i]=fib[i-1]+fib[i-2];
for(int i=0; i<fib.length; i++ )
System.out.println(i+"->"+fib[i]+" ");
System.out.println();
}
}
最大索引值:90
最大值=90
package C1;
public class C1 {
public static void main(String[] args) {
long[] f = new long[100] ;
f[0] = 1;
f[1] = 2;
for(int i = 2; i < f.length; i++)
{f[i] = f[i-1] + f[i-2];}
for(int i = 0; i < f.length; i++)
{System.out.print("f"+i+" "+f[i]);
System.out.println();}
}
}
90為最大值
package C1;
public class C1 {
public static void main(String[] args) {
long[] f = new long[100] ;
f[0] = 1;
f[1] = 2;
for(int i = 2; i < f.length; i++)
{f[i] = f[i-1] + f[i-2];}
for(int i = 0; i < f.length; i++)
{System.out.print("f"+i+" "+f[i]);
System.out.println();}
}
}
package p1;
public class a {
public static void main(String[] args) {
long[] f = new long[100] ;
f[0] = 1;
f[1] = 2;
for(int i = 2; i < f.length; i++)
{f[i] = f[i-1] + f[i-2];}
for(int i = 0; i < f.length; i++)
{System.out.print(" "+f[i]);
System.out.println();} }
}
最大索引值=90
最大值=90
package p1;
public class B1 {
public static void main(String []args){
long f[]=new long [100];
f[0]=1;
f[1]=2;
for ( int i=2;i<f.length;i++)
f[i]=f[i-1]+f[i-2];
for (int i=0;i<f.length;i++)
System.out.println(i+"->"+f[i]+" ");
System.out.println();
}
}
public class B1
{
public static void main(String[] args)
{
long[] f=new long[100];
f[0]=1;
f[1]=2;
for(int i = 2; i < f.length; i++)
f[i] = f[i-1] + f[i-2];
for(int i = 0; i < f.length; i++)
System.out.println("f"+i+"="+" "+f[i]);
System.out.println();
最大值是 f90
public class b9733054 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int i;
long f[]=new long[100];
f[0]=1;
f[1]=2;
for(i=2;i<f.length;i++){
f[i]=f[i-1]+f[i-2];
System.out.println("f["+i+"]="+f[i]);
}
}
}
/*索引最大值到90*/
package gan;
class gan{
public static void main(String[]args){
long[] f = new long[100];
f[0]=1;
f[1]=2;
for(int i = 2; i <f.length;i++) {
f[i] = f[i-1] + f[i-2];
}
for(int i = 0; i < f.length;i++) {
System.out.print("f"+i+ " "+f[i]);
System.out.println();
}
}
}
public class abcd {
public static void main(String[] args) {
long [] f=new long[100];
f[0]=1;
f[1]=2;
for (int i=2;i<f.length;i++)
{
f[i]=f[i-1]+f[i-2];
System.out.println("f["+i+"]"+f[i]);
}
}
}
*****第90個開始出錯*****
public class abc {
public static void main(String[] args)
{
long [] f=new long[100];
f[0]=1;
f[1]=2;
for(int i=2;i<f.length;i++)
{
f[i]=f[i-1]+f[i-2];
System.out.println("["+i+"]"+f[i]);
}
}
}
###到90行以前都是正確的,91行開始出錯出現負號###
package C1;
public class C2 {
public static void main(String[] args) {
⋯⋯
long[] f = new long[100] ;
f[0] = 1;
f[1] = 2;
for(int i = 2; i < f.length; i++)
{f[i] = f[i-1] + f[i-2];}
for(int i = 0; i < f.length; i++)
{System.out.print("f"+i+" "+f[i]);
System.out.println();}
}
}
package B9;
public class b9933016
{
public static void main(String[] args) {
long[] f = new long[100] ;
f[0] = 1;
f[1] = 2;
for(int i = 2; i < f.length; i++)
{f[i] = f[i-1] + f[i-2];}
for(int i = 0; i < f.length; i++)
{System.out.print("f"+i+" "+f[i]);
System.out.println();}
}
}
99
package B9;
public class b9933016
{
public static void main(String[] args) {
long[] f = new long[100] ;
f[0] = 1;
f[1] = 2;
for(int i = 2; i < f.length; i++)
{f[i] = f[i-1] + f[i-2];}
for(int i = 0; i < f.length; i++)
{System.out.print("f"+i+" "+f[i]);
System.out.println();}
}
}
89
package B9;
public class b9933016
{
public static void main(String[] args) {
long[] f = new long[100] ;
f[0] = 1;
f[1] = 2;
for(int i = 2; i < f.length; i++)
{f[i] = f[i-1] + f[i-2];}
for(int i = 0; i < f.length; i++)
{System.out.print(" "+f[i]);
System.out.println();}
}
}
public class Fibonacci
{
public static void main(String[] args)
{
int n=100;
long f[]=new long[n];
f[0]=1;
f[1]=2;
for(int i=2; i<f.length;i++){
f[i]=f[i-1]+f[i-2];
if (f[i]<=f[i-1])
{break;}
System.out.println("f["+i+"]="+f[i]);
}
}
}
public class Fibonacci {
public static void main(String[] args) {
int n=100;
long f[]=new long[n];
f[0]=1;
f[1]=2;
for(int i=2; i<f.length;i++){
f[i]=f[i-1]+f[i-2];
if (f[i]<=f[i-1])
{break;}
System.out.println("f["+i+"]="+f[i]);
}
}
}
public class d1 {
public static void main(String[] args) {
int n=100;
long f[]=new long[n];
f[0]=1;
f[1]=2;
for(int i=2; i<f.length;i++){
f[i]=f[i-1]+f[i-2];
if (f[i]<=f[i-1])
{break;}
System.out.println("f["+i+"]="+f[i]);
}
}
}
public class abcd {
public static void main(String[] args) {
long [] f=new long[100];
f[0]=1;
f[1]=2;
for (int i=2;i<f.length;i++)
{
f[i]=f[i-1]+f[i-2];
System.out.println("f["+i+"]"+f[i]);
}
}
}
public class abcd {
public static void main(String[] args) {
long [] f=new long[100];
f[0]=1;
f[1]=2;
for (int i=2;i<f.length;i++)
{
f[i]=f[i-1]+f[i-2];
System.out.println("f["+i+"]"+f[i]);
}
}
}
package P1;
public class A1
{
public static void main(String[] args)
{
long[] f = new long[100] ;
f[0] = 1;
f[1] = 2;
for(int i = 2; i < f.length; i++)
{f[i] = f[i-1] + f[i-2];}
for(int i = 0; i < f.length; i++)
{System.out.print(" "+f[i]);
System.out.println();}
}
}
public class A1
{
public static void main(String[] args)
{
long[] f=new long[100];
f[0]=1;
f[1]=2;
for(int i = 2; i < f.length; i++)
f[i] = f[i-1] + f[i-2];
for(int i = 0; i < f.length; i++)
System.out.println("f"+i+"="+" "+f[i]);
System.out.println();
最大值是 f90
package P1;
public class A1
{
public static void main(String[] args)
{
long[] f = new long[100] ;
f[0] = 1;
f[1] = 2;
for(int i = 2; i < f.length; i++)
{f[i] = f[i-1] + f[i-2];}
for(int i = 0; i < f.length; i++)
{System.out.print(" "+f[i]);
System.out.println();}
}
}
張貼留言