Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Dl {
- public static void main(String[] args){
- Scanner scan = new Scanner(System.in);
- int n = scan.nextInt();
- int[] a = new int[1];
- a[0]=1;
- int[] b = new int[1];
- b[0]=1;
- int[] c;
- for(int i=3;i<n+1;i++) {
- c = add(a, b);
- a = b;
- b = c;
- out(c);
- }
- }
- public static int[] add(int[] a, int[] b) {
- int max = Math.max(a.length, b.length);
- int[] c = new int [max];
- int d = 0;
- for(int i =0;i<max;i++){
- if(i<a.length){
- c[i]+=a[i];
- }
- if(i<b.length){
- c[i]+=b[i];
- }
- c[i]+=d;
- d=c[i]/10;
- c[i]=c[i]%10;
- }
- if(d>0){
- c[max+1]=d;
- return c;
- }else{
- int [] c1=new int [max];
- for(int i=0; i<max;i++){
- c1[i]=c[i];
- }
- return c1;
- }
- }
- public static void out(int[] c) {
- for(int i=c.length-1;i>=0;i--){
- System.out.print(c[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement