In: Computer Science
Write a program that will print out “W” using a character that a user provides. use for loop statement.
in java please
import java.util.Scanner;
class PatternW
{
// create class for printing inp char.
private static void character(int count,char inp)
{
for (int i = 0; i < count; ++i)
System.out.print(inp);
}
// create class for printing " " space.
private static void spaces(int count)
{
for (int i = 0; i < count; ++i)
System.out.print(" ");
}
public static void main(String[] args)
{
// initialize and create object.
char inp;
Scanner sc=new Scanner(System.in);
System.out.print("Enter the character for pattern : \n");
inp=sc.next().charAt(0);
for (int i = 0; i < 5; ++i)
{
character(i + 1, inp);
spaces(5 - i - 1);
character(5 - i + 1, inp);
spaces(2 * i);
character(5 - i+1, inp);
spaces(5 - i - 1);
character(i + 1, inp);
System.out.println();
}
}
}
I hope it helps.