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
8 Respuestas
+ 4
STOP
Do this:
System.out.print(c);
if (n != 13)
System.out.print(",");
+ 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);
}
}
+ 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);
+ 1
thank you all
+ 1
STOP
My answer will work in both cases.
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;
}
}
}
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;
}
}
}
- 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;
}
}
}