Am i right on Fibonacci sequence? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Am i right on Fibonacci sequence?

package fib; import java.util.*; public class fib{ public static void main(String[]args){ Scanner vip = new Scanner(System.in); int t1 =0; int t2= 1; System.out.println("enter number of time to be carried out"); int n = vip.nextInt(); System.out.println("your fibonaccis sequence is"); System.out.print("first " + n + " terms: "); for (int i=1; i <= n; ++i) { System.out.print(t1 + " + "); int sum = t1 + t2; t1 = t2; t2 = sum; } } }

30th Jun 2018, 7:02 PM
LATIVISTER
LATIVISTER - avatar
4 Answers
+ 4
yes, surely pre-increment and post-increment makes a huje difference
23rd Sep 2018, 7:29 PM
#DARK_PROGRAMMER_✔
#DARK_PROGRAMMER_✔ - avatar
+ 2
yes it has an effect as u initized a variable i with 1 if you use ++i then it will first incrememt to 2 before proceding, if you use i++ then it will increment to 2 after loop execution for first time
23rd Jul 2018, 6:38 PM
#DARK_PROGRAMMER_✔
#DARK_PROGRAMMER_✔ - avatar
+ 1
yes but there is 1 logical error... you must use post-increment i.e use "i++" instead of "++".
30th Jun 2018, 9:58 PM
#DARK_PROGRAMMER_✔
#DARK_PROGRAMMER_✔ - avatar
+ 1
ok...but does that have effect on the program
1st Jul 2018, 11:00 AM
LATIVISTER
LATIVISTER - avatar