Answered step by step
Verified Expert Solution
Link Copied!

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.

image text in transcribed

My output of this code is as follows:

image text in transcribed

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 27

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Microsoft SQL Server 2012 Programming

Authors: Paul Atkinson, Robert Vieira

1st Edition

1118102282, 9781118102282

More Books

Students also viewed these Databases questions

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago