vendredi 2 mars 2018

Pattern Printing

I like to print a pattern in java which gives the output:

1
23
456
78910  ....

But i am not getting how to do this, I wrote a program to print pattern of

1
12
123
1234 ...

as

import java.util.*;
public class Test {

public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int r,c;
for(r=1;r<=5;r++) {
        for(c=1;c<=r;c++){
        System.out.print(c+" ");
    }

    System.out.println();   
}}}

Getting that last number on each row and start from that number on the second row is what I am having trouble with. I tried adding an another for loop in between the other but it didn't help.Can anyone get me what I am missing and how to do this!

Aucun commentaire:

Enregistrer un commentaire