0

java print ask

https://code.sololearn.com/cDmvME3nyACS on this code, I don't want this ", " after the last number, how can I make the output like this 0 , 1 , 1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 , 55 , 89 , 144

11th Sep 2021, 5:51 PM
STOP
STOP - avatar
8 Antworten
+ 4
STOP Do this: System.out.print(c); if (n != 13) System.out.print(",");
11th Sep 2021, 6:03 PM
A͢J
A͢J - avatar
+ 2
Try this public class Program { public static void main(String[] args) { int a,b,c,n;a=0;b=1;c=0;n=3; System.out.print(a + ","); System.out.print(b); do { c=a+b; System.out.print(","+ c); a=b; b=c; n=n+1; } while(n<=13); } }
11th Sep 2021, 6:07 PM
Pariket Thakur
Pariket Thakur - avatar
+ 1
Try this: (changed print statements for a, b, and c) System.out.print(a); System.out.print("," + b); do { c=a+b; System.out.print("," + c);
11th Sep 2021, 6:04 PM
Coding Cat
Coding Cat - avatar
+ 1
thank you all
11th Sep 2021, 6:11 PM
STOP
STOP - avatar
+ 1
STOP My answer will work in both cases.
11th Sep 2021, 6:30 PM
A͢J
A͢J - avatar
0
STOP u can try this public class Program { public static void main(String[] args) { int a=0; int c=0; int b=1; for(int i=1;i<=10;i++) { c=a+b; System.out.print(c); if(i!=10) { System.out.print(","); } b=a; a=c; } } }
11th Sep 2021, 6:22 PM
Pariket Thakur
Pariket Thakur - avatar
0
STOP See this. Now you can just change len value. public class Program { public static void main(String[] args) { int a = 0; int c = 0; int b = 1; int len = 10; for(int i = 1; i <= len; i++) { c = a + b; System.out.print(c); if (i != len) System.out.print(", "); b = a; a = c; } } }
11th Sep 2021, 6:34 PM
A͢J
A͢J - avatar
- 1
and how can i make it with this code ?? public class Program { public static void main(String[] args) { int a=0; int c=0; int b=1; for(int i=1;i<=10;i++) { c=a+b; System.out.print(" , " +c); b=a; a=c; } } }
11th Sep 2021, 6:14 PM
STOP
STOP - avatar