🌙 DARK

Number Pattern Program In Java

 

Number Pattern

Write a program to print the below pattern.

If n = 3, pattern will be

1 1 1 2
3 2 2 2
3 3 3 4


Input Format:

Input consists of an integer n.

Output Format:

Print the desired pattern.

[All text in bold corresponds to input and the rest corresponds to the output.]
 

Sample Input and Output 1:

3
1 1 1 2
3 2 2 2
3 3 3 4


Sample Input and Output 2:

4
1 1 1 1 3
4 2 2 2 2
3 3 3 3 5
6 4 4 4 4

PROGRAM:-
@MRProgrammer 


CREATE CLASS < Main :

import java.util.Scanner;

public class Main{

    public static void main(String[] args){             

         Scanner sc = new Scanner(System.in);

         int n = sc.nextInt();

         int temp = n-1,a=0;

         for(int i=1;i<=n;i++)

         {

             for(int j=1;j<=n+1;j++)

             {

                 if(j==n+1 && a==0)

                 {

                     System.out.print(temp);

                     

                }

                 

                 else if(j==1 && a==1)

                 {

                     System.out.print(temp+" ");

                    

                 }

                 else  

                    System.out.print(i+" ");

                 

                 

             }

             

             if(a==0)

             {

                 a++;

                 temp++;

             }

             else{

                 a=0;

                 temp++;

             }

             System.out.println();

         }

         

    }

}


Question 2)


Ticket type
 

"Zebra Kingdom" is a brand new Amusement park that is going to be inaugurated shortly in the city and is promoted as the place for breath-taking charm. The theme park has more than 30 exhilarating and craziest rides and as a special feature of the park, the park Authorities have placed many Ticketing Kiosks at the entrance which would facilitate the public to purchase their entrance tickets and ride tickets.
 
The Entrance Tickets are to be issued typically based on age, as there are different fares for different age groups. There are 2 types of tickets – Child ticket and Adult ticket. If the age given is less than 15, then a Child ticket is issued whereas, for an age greater than equal to 15, an Adult ticket is issued. Write a piece of code to program this requirement in the ticketing kiosks.


 
Input Format:

The first line of the input is an integer that corresponds to the age of the person.

Output Format:

The output should display "Child Ticket" or "Adult Ticket" based on the conditions given.
Refer sample input and output for formatting specifications.

 

[All text in bold corresponds to input and the rest corresponds to the output.]
 

Sample Input and Output 1:

20
Adult Ticket


Explanation:

20 is greater than 15, so the output is “ Adult Ticket ”.

Sample Input and Output 2:

12
Child Ticket


Explanation:

12 is less than 15, so the output is “ Child Ticket ”.


PROGRAM:-
@MRProgrammer 


CREATE CLASS < Main :

import java.util.Scanner;


public class Main{

    public static void main(String[] args){         

           Scanner sc = new Scanner(System.in);

           System.out.println("");

           int age = sc.nextInt();

           if(age<15) {

           System.out.println("Child Ticket");

           }

           else if(age>=15) {

           System.out.println("Adult Ticket");

           }

    }

}


@MRProgrammer 






MOTIVATION :


    “The way we spend our time defines who we are 


Although we may not see each other as often as we’d like, distance is no match for the bond that we share. Thank you for coming to visit. It was fantastic to catch up.


VISITE MORE BLOGS




THANK YOU....😊


Post a Comment

Thanks for reading the blog. We hope it was useful to you and that you learned something new. Will always be writing on new and interesting topics, so you can visit our website to know the latest updates of our blogs. Thank You!

Previous Post Next Post

Contact Form