+ 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; } } }
4 Réponses
+ 4
yes, surely pre-increment and post-increment makes a huje difference
+ 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
+ 1
yes but there is 1 logical error...
you must use post-increment i.e use "i++" instead of "++".
+ 1
ok...but does that have effect on the program