Write a shell program to print the following pattern:
1
10
101
1010
10101
Answers
Answered by
1
Answer:
It is written half after you can create by yourself
Attachments:
Answered by
1
1
10
101
1010
10101
Explanation:
import java.util.Scanner;
public class abc
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
System.out.print("Enter n: ");
int n = scanner.nextInt();
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= i; j++)
{
if (j % 2 == 1)
{
System.out.print("1 ");
}
else
{
System.out.print("0 ");
}
}
System.out.println();
}
}
}
Similar questions