Question

In: Computer Science

Write a program that will print out “W” using a character that a user provides. use...

Write a program that will print out “W” using a character that a user provides. use for loop statement.

in java please

Solutions

Expert Solution

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.


Related Solutions

Write java program that will ask for the user for 2 input lines and print out...
Write java program that will ask for the user for 2 input lines and print out all words that occur 1 or more times on both lines (case sensitive). Write this without arrays and method. Here is a sample run: <Output> Enter two lines to process. The quick brown fox jumps over a lazy dog The fox hound outruns the lazy dog The words that occur on both lines are: The fox lazy dog
1. Write a program that will ask the user to enter a character and then classify...
1. Write a program that will ask the user to enter a character and then classify the character as one of the following using only IF-ELSE and logical operators. (50 points - 10pts for syntax, 10pts for commenting and 30pts for successful execution) • Integer • Lower Case Vowel • Upper Case Vowel • Lower Case Consonant • Upper Case Consonant • Special Character
Objectives: Write a program which reads User Input using Scanner Print formatted output using printf or...
Objectives: Write a program which reads User Input using Scanner Print formatted output using printf or DecimalFormat Practice programming simple mathematical calculations Instructions: Samwise Gamgee has finally decided to submit his expense report for all of his adventures regarding his travels to Mordor. Part of those expenses are his stay at the Prancing Pony Inn located in Bree. You are to write a simple Java program which will generate an Invoice for his stay at the Inn. Your program should...
Write a program that will print the whole numbers from a user-specified minimum to a user-specified...
Write a program that will print the whole numbers from a user-specified minimum to a user-specified maximum. Display the total amount of numbers printed.
how to write a cpp program that takes a number from a user, and print the...
how to write a cpp program that takes a number from a user, and print the sum of all numbers from one to that number on screen? using loop interation as basic as possible.
PYTHON: Write a program that asks the user to enter a 10-character telephone number in the...
PYTHON: Write a program that asks the user to enter a 10-character telephone number in the format XXX-XXX-XXXX. The application should display the telephone number with any alphabetic characters that appeared in the original translated to their numeric equivalent. For example, if the user enters 555-GET-FOOD, the application should display 555-438-3663. This is my code, but I cannot figure out where to go from here. #set new number new_number = "" #split number split_num = phone.split("-") for char in split_num[1:2]:...
Write a complete Java program to print out the name bob
Write a complete Java program to print out the name bob
Write a Python program which prompts the user to input a string. Then, print the string...
Write a Python program which prompts the user to input a string. Then, print the string in reverse to the terminal Sample output Please enter a word: "zeus" The reverse of zeus is suez Hint: There are several ways to accomplish this. Recall that a string is an itterable object and therefore can be used with a for loop
Write a mips assembly language program that asks the user to enter an alphabetic character (either...
Write a mips assembly language program that asks the user to enter an alphabetic character (either lower or upper case)and change the case of the character from lower to upper and from upper to lower and display it.
Write an assembly language program that will print out the message of your choosing #NOTE #write...
Write an assembly language program that will print out the message of your choosing #NOTE #write in a simple way, so that i can execute it from command window using masm
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT