Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output simplified #40

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 35 additions & 10 deletions Fibonacci.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,39 @@
public class Fibonacci{

public static void main(String []args){
int start = Integer.parseInt(args[0]);
BigInteger fib1 = new BigInteger("0");
BigInteger fib2 = new BigInteger("1");
for(int i = 0; i <= (start -2); i++) {
BigInteger fib3 = fib1.add(fib2);
System.out.println("F"+ i + " = " + fib1 + ", F" + (i+1) + " = " + fib2 + ", F" + (i+2) + " = " + fib3);
fib1 = fib2;
fib2 = fib3;
}

int start = 0;


try{
if(args.length > 0){
start = Integer.parseInt(args[0]);
}

}catch(NumberFormatException e){
e.printStackTrace();
}

if(start > 2){

long startTime = System.currentTimeMillis();

BigInteger fib1 = new BigInteger("0");
BigInteger fib2 = new BigInteger("1");


System.out.println("F" + 0 + " = " + fib1);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent가 맞지 않습니다.

System.out.println("F" + 1 + " = " + fib2);

for(int i = 0; i <= (start -2); i++) {
BigInteger fib3 = fib1.add(fib2);
System.out.println("F" + (i+2) + " = " + fib3);
fib1 = fib2;
fib2 = fib3;
}

long endTime = System.currentTimeMillis();
System.out.println("Execution time : " + ((endTime - startTime)/1000.0) + "sec" );
}
}
}
}