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

In java coding, write a program that will print out a representation of a “W” using...
In java coding, write a program that will print out a representation of a “W” using a character that a user provides.
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
***Using Java Using the switch/case construct, write a program that takes a character from the user...
***Using Java Using the switch/case construct, write a program that takes a character from the user and classifies it as a number (‘1’,’2’, ‘3’, …), a letter from the alphabet (‘A’, ‘a’, ‘B’, ‘b’, …, ‘Z’, ‘z’), an arithmetic operator (‘+’, ‘-‘, ‘/’, ‘*’, ‘%’), a comparison operator (‘<’, ‘>’, ‘=’), punctuation (‘!’, ‘?’, ‘,’, ‘,’, ‘:’, ‘;’), and all other characters as a Special Character, and informs the user of the same. If the user entered the character A,...
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
Write a program that allows the user to enter two integers and a character If the...
Write a program that allows the user to enter two integers and a character If the character is A, add the two integers If it is S, subtract the second integer from the first else multiply the integers Display the results of the arithmetic
In java, write a program that asks the user to enter a character. Then pass the...
In java, write a program that asks the user to enter a character. Then pass the character to the following methods. isVowel() – returns true if the character is a vowel isConsonant() – returns true if the character is a consonant changeCase() – if the character is lower case then change it to upper case and if the character is in upper case then change it to lower case. (return type: char) Example output is given below: Enter a character...
write a program to calculate and print payslips write program that calculates and prints payslips. User...
write a program to calculate and print payslips write program that calculates and prints payslips. User inputs are the name of employee, numbers of hours worked and hourly rate c++ language
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.
Create a python program that will ask the user for his job title and print out...
Create a python program that will ask the user for his job title and print out the first letter, the last letter and the total number of letters in his job
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT