- 2

Can you please help me out with this pattern in java

1 11 112 1123 11235 112358

19th Jun 2020, 1:52 PM
Pranjal Bose
5 Respuestas
+ 6
Show your attempt first. Hint: Is the difference between the digits saying something?
19th Jun 2020, 2:02 PM
Harsh
Harsh - avatar
+ 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.
19th Jun 2020, 2:53 PM
Harsh
Harsh - avatar
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 (); } } }
19th Jun 2020, 2:22 PM
Pranjal Bose
0
class Test { public static void main(String arg[]) { int h=10;
19th Jun 2020, 7:51 PM
zemiak