Welcome to ICSE Java Answers. Ask any questions you have related to Java and we will answer them.
Java is a registered trademark of Oracle. This site is in no way related to or endorsed by Oracle.

print the pattern 1 10 101 1010 10101

0 votes
asked by anonymous

2 Answers

0 votes

Code for the pattern to print n number of times:

import java.util.*;
public class Pattern_1
{
    public static void main()
    {
        int a=1,b=0,n;
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter number of times you want to print the pattern:");
        n=sc.nextInt();
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=i;j++)
            {
                if(j%2!=0)
                {
                    System.out.print(a);
                }
                else
                {
                    System.out.print(b);
                }
            }
            System.out.print(" ");
        }
    }
}
answered by Anonymous_1 (85 points)
0 votes
import java.util.Scanner;
class g 
{
    public static void main(String[]args)
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=i;j++)
            {
                if(j%2==0)
                {
                    System.out.print("0");
                }
                else{
                    System.out.print("1");
                }
            }
            System.out.print(" ");
        }
    }
}
answered by Somi setty Sreekar
...