Himucode for kids

Pattern Generation Programs


Question 1

WAP to input a number n and print the following pattern uptil n lines

1
11
111
1111
11111
111111
In this example n = 6

java

        
            
import java.util.*;
public class Test
{
public static void main()
{
    int i, j, n;
    Scanner sc = new Scanner(System.in);
    
    System.out.println("enter the number of lines");
    n = sc.nextInt();
    
    for (i = 1; i<= n; i++)
    {
        for (j = 1; j <= i; j++)
            System.out.print("1");
        System.out.println();
    }
}
}

        
        

python

        
            
n = int(input("Enter the number of lines: "))

for i in range(1, n + 1, 1):
    for j in range(1, i + 1, 1):
        print('1', end = ' ')
print()

        
        


Question 2

WAP to input a number n and print the following pattern uptil n lines

1
12
123
1234
12345
123456
In this example n = 6

java

        
            
import java.util.*;
public class Test
{
public static void main()
{
    int i, j, n;
    Scanner sc = new Scanner(System.in);
    
    System.out.println("enter the first number");
    n = sc.nextInt();
    
    for (i = 1; i<= n; i++)
    {
        for (j = 1; j <= i; j++)
            System.out.print(j);
        System.out.println();
    }
}
}

        
        

python

        
            
n = int(input("Enter the number of lines: "))

for i in range(1, n + 1, 1):
    for j in range(1, i + 1, 1):
        print(j, end = ' ')
    print()

        
        


Question 3

WAP to input a number n and print the following pattern uptil n lines

123456
12345
1234
123
12
1
In this example n = 6

java

        
            //Oops! solution pending...
        
        

python

        
            #Oops! solution pending...
        
        


Question 4

WAP to input a number n and print the following pattern uptil n lines

1
22
333
4444
55555
In this example n = 5

java

        
            
import java.util.*;
public class Test
{
public static void main()
{
    int i, j, n;
    Scanner sc = new Scanner(System.in);
    
    System.out.println("enter the first number");
    n = sc.nextInt();
    
    for (i = 1; i<= n; i++)
    {
        for (j = 1; j <= i; j++)
            System.out.print(i);
        System.out.println();
    }
}
}

        
        

python

        
            
n = int(input("Enter the number of lines: "))

for i in range(1, n + 1, 1):
    for j in range(1, i + 1, 1):
        print(i, end = ' ')
    print()

        
        


Question 5

WAP to input a number n and print the following pattern uptil n lines

 XXXXX
    XXXX
       XXX
          XX
             X

In this example n = 5

java

        
            //Oops! solution pending...
        
        

python

        
            #Oops! solution pending...
        
        


Question 6

WAP to input a number n and print the following pattern uptil n lines

        1
      21
    321
  4321
54321
In this example n = 5

java

        
            //Oops! solution pending...
        
        

python

        
            #Oops! solution pending...
        
        


Question 7

WAP to input a number n and print the following pattern uptil n lines

1
10
101
1010
10101
In this example n = 5

java

        
            
import java.util.*;
public class Test
{
public static void main()
{
    int i, j, n, x;
    Scanner sc = new Scanner(System.in);
    
    System.out.println("enter the first number");
    n = sc.nextInt();
    
    for (i = 1; i<= n; i++)
    {
        for (j = 1; j <= i; j++)
        {
            x = j % 2;
            System.out.print(x);
        }
        System.out.println();
    }
}
}

        
        

python

        
            
n = int(input("Enter the number of lines: "))

for i in range(1, n + 1, 1):
    for j in range(1, i + 1, 1):
        x = j % 2 
        print(x, end = ' ')
    print()

        
        


Question 8

WAP to input a number n and print the following pattern uptil n lines

1
31
531
7531
97531
In this example n = 5

java

        
            //Oops! solution pending...
        
        

python

        
            #Oops! solution pending...