Computer Science, asked by yashs8979, 4 days ago

Write a program (Using scanner class) to generate a pattern of a token / word in the form of a traiangle or in the form of an inverted triangle depending upon the user’s choice. Sample input : Enter a word as a token CLASS Sample output: Enter your choice: 1
C
C L
C L A
C L A S
C L A S S​
pls tell it's very urgent it's for assignment

Answers

Answered by aadivyraj
3

Please mark me as brainlist

import java.util.Scanner; public class KboatPattern { public static void main(String args[]) { Scanner in = new Scanner(System.in); System.out.println("1. Triangle"); System.out.println("2. Inverted Triangle"); System.out.print("Enter your choice: "); int choice = in.nextInt(); switch (choice) { case 1: for (int i = 1; i <= 5; i++) { for (int j = 1; j <= i; j++) { System.out.print("* "); } System.out.println(); } break; case 2: for (int i = 5; i >= 1; i--) { for (int j = 1; j <= i; j++) { System.out.print("* "); } System.out.println(); } break; default: System.out.println("Invalid Choice"); break; } } }

Answered by anshbagul79
0

Answer:

Write a program (using scanner class) to generate a pattern of a token in the form of a triangle or in the form of an inverted triangle depending upon the user's choice.

Sample Input/Output:

Enter your choice 1

*

* *

* * *

* * * *

* * * * *

Enter your choice 2

* * * * *

* * * *

* * *

* *

*

KnowledgeBoat Logo

Computer Applications

Write a program (using scanner class) to generate a pattern of a token in the form of a triangle or in the form of an inverted triangle depending upon the user's choice.

Sample Input/Output:

Enter your choice 1

*

* *

* * *

* * * *

* * * * *

Enter your choice 2

* * * * *

* * * *

* * *

* *

*

→→

ANSWER

import java.util.Scanner;

public class KboatPattern

{

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.println("1. Triangle");

System.out.println("2. Inverted Triangle");

System.out.print("Enter your choice: ");

int choice = in.nextInt();

switch (choice) {

case 1:

for (int i = 1; i <= 5; i++) {

for (int j = 1; j <= i; j++) {

System.out.print("* ");

}

System.out.println();

}

break;

case 2:

for (int i = 5; i >= 1; i--) {

for (int j = 1; j <= i; j++) {

System.out.print("* ");

}

System.out.println();

}

break;

default:

System.out.println("Invalid Choice");

break;

}

}

}

Similar questions