Write a method to display a big \"X\" using ascii characters. The method header
ID: 3849166 • Letter: W
Question
Write a method to display a big "X" using ascii characters. The method header is: public static void display(int n) where the n is how many rows tall it is. You can use this code as a template for your solution: import java.util.Scanner: public class Pattern { public static void main (String[] args){ Scanner input = new Scanner (System in): System.out.print("Enter number of lines, n: "): int n = input.nextInt(): displayPattern (n): } public static void displayPattern (int n) { //Fill in code here } }Explanation / Answer
Pattern.java
import java.util.Scanner;
public class Pattern {
public static void main(String[] args) {
// Scanner object is used to get the inputs entered by the user
Scanner input = new Scanner(System.in);
// Getting the inputs entered by the user
System.out.print("Enter number of lines, n:");
int n = input.nextInt();
// calling the method entered by the user
displayPattern(n);
}
// This method will display the pattern 'X'
private static void displayPattern(int n) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if ((i == j) || (j == (n - 1) - i)) {
System.out.print((char) 120);
} else {
System.out.print(" ");
}
}
System.out.println();
}
}
}
______________________
Output:
Enter number of lines, n:6
x x
x x
xx
xx
x x
x x
____________________
Output2:
Enter number of lines, n:7
x x
x x
x x
x
x x
x x
x x
_____________Could you rate me well.Plz .Thank You
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.