belongs to collection: Java programs to print patterns
Program 4) Print the following pattern
1 10 101 1010 10101
Program
import java.util.Scanner; public class Pattern4 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter number of rows: "); int rows = sc.nextInt(); System.out.println("Here is your pattern....!!!"); for (int i = 1; i <= rows; i++) { for (int j = 1; j <= i; j++) { if(j%2 == 0) { System.out.print(0); } else { System.out.print(1); } } System.out.println(); } sc.close(); } }
Output
Enter number of rows: 5 Here is your pattern....!!! 1 10 101 1010 10101
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Program
Output