Problem #5: This one is a challenge!! Write a program that will print out a representation of the University of Washington “W” using a character that a user provides.
ANSWER:-
GIVEN THAT:-
import java.util.Scanner;
public class Wpattern {
private static void YourCharacter(int count,
char ch)
{
for (int i = 0;
i < count; ++i)
System.out.print(ch);
}
private static void
betweenSpaces(int count)
{
for (int i = 0; i < count;
++i)
System.out.print(" ");
}
public static void main(String[]
args)
{
int n;
Scanner scan=new
Scanner(System.in);
// That is your number of
rows
System.out.print("Enter the number
for pattern : ");
n=scan.nextInt();
System.out.println("Enter your
special character: ");
char
ch=scan.next().charAt(0);
for (int i = 0; i < n;
++i)
{
YourCharacter(i
+ 1,ch);
betweenSpaces(n - i - 1);
YourCharacter(n - i + 1, ch);
YourCharacter(2 * i, ch);
YourCharacter(n - i,ch);
betweenSpaces(n - i - 1);
YourCharacter(i + 1, ch);
System.out.println();
}
}
}
OUTPUT:-
Get Answers For Free
Most questions answered within 1 hours.