Question: How do I fix this code so that it outputs a shape based off the user inputting an odd or even number? Example: User Input:
How do I fix this code so that it outputs a shape based off the user inputting an odd or even number?
Example:
User Input: 10
Enter the triangle height: 10
()
()()
()()()
()()()()
()()()()()
()()()()()()
()()()()()()()
()()()()()()()()
()()()()()()()()()
()()()()()()()()()()
import java.util.Scanner;
public class ReverseTriangle { public static void main(String[] args) { System.out.println("Enter the triangle height: "); Scanner userInput = new Scanner(System.in); int userInt = userInput.nextInt(); userInput.close();
if (userInt == 0) { System.out.println("Zero is an invalid height."); } else if (userInt < 0) { System.out.println("A negative height isn't valid."); } else if (userInt % 2 == 0){ userInt = evenNum; } else { userInt = oddNum; /* Edit code */ }
System.out.print(oddNum + "***"); System.out.print(evenNum + "*"); /* Write your code here */ } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
