Home I Chegg.comX 3991-dt content-rid-1760358_1/courses/85763/cis214exam02h.rpdf
ID: 3905001 • Letter: H
Question
Home I Chegg.comX 3991-dt content-rid-1760358_1/courses/85763/cis214exam02h.rpdf Use your Java Development Kit (UDK) to create a Command-Line Interface (CLUI) program that satisfies the following: 1. When the program is executed on a console (eg, Command Prompt on Windows 10 or Terminal on 2. The program then asks the user to select either a normal triangle or an inverted triangle. if the user 3. Next, the program asks the user as to whether he/she wants to continue or not. Iif the user MacOS), it asks a user to enter a number based on which a triangle shape is drawn on a console window. The number is used as the number of lines of the shape. enters n, a normal triangle is displayed. If i is entered, an inverted triangle is displayed. C, the program repeats. If the user enters any character but c or C, the program stops ax Command Prompt cis214 java Exama2TomJones nter a number: 3 Enter n for normal triangle; i for inverted triangle: n nter c or C to continue or any other key to quit: c nter a number: 4 nter n for normal triangle; i for inverted triangle: f inter c or c to continue or any other key to quit: c Enter a number:s inter n for hormal triangle; i for Inverted triangle wrone selection! ter c or c to continue or any other key to quit: q cis214 code file, include comments with your name, course number/name/section, and the honest statement (I, your name here, wrote the program by myself and did not copy othe complete the exam. Save your lava source code name is Tom Jones). You should compile and e submitting your source code file. if it works correctly, submit your source co Use all your knowledge that you have learned in this course to e as Exam02YourName java (eg. Examo2Tomiones java if your deExplanation / Answer
here is your program : ---------->>>>>>>>
import java.util.Scanner;
public class PrintTriangle{
public static void printSimple(int n){
for(int i = 0;i<n;i++){
for(int j = 0;j < (n-i-1);j++){
System.out.print(" ");
}
for(int j = 0;j < (i+i+1);j++){
System.out.print("*");
}
System.out.println();
}
}
public static void printInverted(int n){
for(int i = n-1;i>=0;i--){
for(int j = 0;j < (n-i-1);j++){
System.out.print(" ");
}
for(int j = 0;j < (i+i+1);j++){
System.out.print("*");
}
System.out.println();
}
}
public static void main(String[] args) {
int n = 0;
char I = '0';
char check = 'c';
Scanner sc = new Scanner(System.in);
while(check == 'c'){
System.out.print(" Enter a Number : ");
n = sc.nextInt();
System.out.print(" Enter n for normal Triangle ; i for inverted Triangle : ");
I = sc.next().toLowerCase().charAt(0);
if(I == 'n'){
printSimple(n);
}else if(I == 'i'){
printInverted(n);
}
System.out.print(" Enter c or C to continue or any other key to quit : ");
check = sc.next().toLowerCase().charAt(0);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.