Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class Input{
- int getInput(String prompt){
- System.out.print(prompt);
- Scanner sc = new Scanner(System.in);
- if(!sc.hasNextInt())
- System.out.println("Enter a whole number.");
- else return sc.nextInt();
- return 0;
- }
- }
- class PatternOne{
- public static void main(String args[]){
- int n = new Input().getInput("Enter the number of rows: ");
- for(int i = 0; i < n; i++){
- for(int j = 0; j <= i; j++){
- if((i+j+1)%2 == 0) System.out.print(0);
- else System.out.print(1);
- }
- System.out.println();
- }
- }
- }
- /*Output:-
- Enter the number of rows: 5
- 1
- 01
- 101
- 0101
- 10101 */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement