Computer Science, asked by CuteSiddhi, 1 year ago

pls answer this urgently....

Attachments:

QGP: Wait a few minutes. I am answering

Answers

Answered by QGP
1
Hey There, Here are the codes for both the patterns:



public class P1
{
    public static void main(String[] args)
    {
        int k=1;
        for(int i=1;i<=5;i++)
        {
            for(int j=5;j>=i;j--)
            {
                System.out.print(k+" ");
                if((k/10)==0)
                {
                    System.out.print(" ");
                }
                k++;
            }
            System.out.println();
        }
    }
}


____________________________________________________________

public class P2{
    public static void main(String[] args)
    {
        for(int i=1;i<=5;i++)
        {
            for(int j=1;j<=i;j++)
            {
                System.out.print((j%2)+" ");
            }
            System.out.println();
        }        
    }
}


___________________________________________

Hope it helps
Brainly Community



QGP: P2 is, well, should be simpler. There are 5 rows taken care of by int i
QGP: int j stores the value about how many numbers we have to print in each row
QGP: Now, since we just want to print 0 and 1, I simply took remainder of each iteration of j by 2. This way I can get alternate 0 and 1
CuteSiddhi: ooooohk.....thans just this only i wanted to ask.......thanku........
QGP: You are welcome :)
CuteSiddhi: in which class you r
Phor: 13
QGP: Haha! I just passed 12th
Phor: WHICH BOARD?
QGP: Gujarat State Board.
Similar questions