- 2
Can you please help me out with this pattern in java
1 11 112 1123 11235 112358
5 Respuestas
+ 6
Show your attempt first.
Hint: Is the difference between the digits saying something?
+ 6
Two things to note:
a) You haven't defined h in the first for loop, perhaps you wanted it to store user input?
b) The main method is missing "String[] args" as its parameter. (It doesn't have to be "args", it could be some other string too.)
The program is correct, the only thing you need to do is to use "System.out.print()" inside the loop instead of "System.out.println()" as you do not want the cursor to move to a new line there.
0
class Test
{
public static void main ()
{
for (int i=1;i <=h;i++)
{
int a=0,b=1,c=0;
for (int j=1;j <=i;j++)
{c=a+b;
System.out.println (c);
b=a;
a=c;
}
System.out.println ();
}
}
}
0
class Test {
public static void main(String arg[]) {
int h=10;