Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Could somebody help me with this code for JAVA?! Needs to be in Java code!! Patterns (Patterns.java) Write a method to display a pattern as
Could somebody help me with this code for JAVA?! Needs to be in Java code!!
Patterns (Patterns.java)
Write a method to display a pattern as follows:
0
1 0
2 1 0
:
:
n n-1 2 1 0
The method header is:
public static void displayPattern(int n)
TAKE A SCREENSHOT of the console window showing the above sample run.
What I have for my code:
I have this as my code but I can't seem to put the output in the format of the pattern as above to be right aligned.
My output of this code is as follows:
Patterns.java 3 1 import java.util.Scanner; 3 public class Patterns 4 5e public static void main(String[l args) Scanner input - new Scanner(System.in); 7 System.out.print( Enter the number of rows: "); int n = input.nextInt(); displayPattern(n); // calling the displayPatten function passing n entered by user 10 12 public static void displayPattern(int n) { 13 14 15 16 int padding n - 1; //Holds the number of whitespaces for (int r = 0; r - 0; i--) f 18 19 20 21 System.out.print(i + ""); System.out.println); padding --; 23 24 25 26 27Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started