1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
daser333 [38]
3 years ago
7

19. Squares. Write a program class named SquareDisplay that asks the user for a positive integer no greater than 15. The program

should then display a square on the screen using the character ‘X’. The number entered by the user will be the length of each side of the square. For example, if the user enters 5, the program should display the following: XXXXX XXXXX XXXXX XXXXX XXXXX INPUT and PROMPTS. The program prompts for an integer as follows: "Enter an integer in the range of 1-15: ". OUTPUT. The output should be a square of X characters as described above. CLASS NAMES. Your program class should be called SquareDisplay
Computers and Technology
1 answer:
Mrrafil [7]3 years ago
3 0

Answer:

// program in java.

// package

import java.util.*;

// class definition

class SquareDisplay

{

// main method of the class

public static void main (String[] args) throws java.lang.Exception

{

   try{

    // variable

       int num;

       // scanner object to read input

Scanner scr=new Scanner(System.in);

System.out.print("Enter an integer in the range of 1-15:");

 // read integer from user

num=scr.nextInt();

 // read until input is not in range 1-15

while(num<0 || num>15)

{

    System.out.print("wrong input!!enter again:");

     // read again

    num=scr.nextInt();

}

// print square of X

for(int a=1;a<=num;a++)

{

    for(int b=1;b<=num;b++)

    {

        System.out.print("X");

    }

    System.out.println();

}  

   }catch(Exception ex){

       return;}

}

}

Explanation:

Read an integer from user and assign it to variable "num".Check if input is not  in range 1-15 then ask again until user enter a number between 1-15 only.Then  print a square of character "X" with the help of two nested for loops.

Output:

Enter an integer in the range of 1-15:-4                                                                                  

wrong input!!enter again:20                                                                                                

wrong input!!enter again:4                                                                                                

XXXX                                                                                                                      

XXXX                                                                                                                      

XXXX                                                                                                                      

XXXX

You might be interested in
Write a programmer defined function that compares the ASCII sum of two strings. To compute the ASCII sum, you need to compute th
MariettaO [177]

Answer:

The program in Python is as follows:

def ASCIIsum(str1,str2):

   asciisum1 = 0;    asciisum2 = 0

   for chr in str1:

       asciisum1 += (ord(chr) - 96)

   for chr in str2:

       asciisum2 += (ord(chr) - 96)

   if asciisum1 > asciisum2:

       return True

   else:

       return False

str1 = input("Enter first string: ")

str2 = input("Enter second string: ")

if ASCIIsum(str1,str2) == True:

   print(str1,"has a higher ASCII value")

else:

   print(str2,"has a higher ASCII value")

Explanation:

This defines the function

def ASCIIsum(str1,str2):

This initializes the ascii sum of both strings to 0

   asciisum1 = 0;    asciisum2 = 0

This iterates through the characters of str1 and add up the ascii values of each character

<em>    for chr in str1:</em>

<em>        asciisum1 += (ord(chr) - 96)</em>

This iterates through the characters of str2 and add up the ascii values of each character

<em>    for chr in str2:</em>

<em>        asciisum2 += (ord(chr) - 96)</em>

This returns true if the first string has a greater ascii value

<em>    if asciisum1 > asciisum2:</em>

<em>        return True</em>

This returns false if the second string has a greater ascii value

<em>    else:</em>

<em>        return False</em>

The main begins here

This gets input for first string

str1 = input("Enter first string: ")

This gets input for second string

str2 = input("Enter second string: ")

If the returned value is True

if ASCIIsum(str1,str2) == True:

Then str1 has a greater ascii value

   print(str1,"has a higher ASCII value")

If otherwise

else:

Then str2 has a greater ascii value

   print(str2,"has a higher ASCII value")

3 0
3 years ago
If needed, you can pull over on the shoulder of the freeway to take a break if you are tired. true or false (drivers ed) need as
wel

Answer:

True

Explanation:

If you feel you are a hazard to others on the road you can use the shoulder to get off of the road, thats what they are meant for.

3 0
3 years ago
Assume the existence of a Building class with a constructor that accepts two parameters:_________ a reference to an Address obje
Maksim231197 [3]

Answer:

class Building { int toatalUnit; Building(Building add, int x) { } } public class ApartmentBuilding extends Building { int toatalUnit; ApartmentBuilding(ApartmentBuilding add, int a, int b) { super(add, b); this.toatalUnit = b; } }

Explanation:

Assume the existence of a Building class with a constructor that accepts two parameters:_________ a reference to an Address object representing the building's address, and an integer for the square footage of the building. Assume a subclass ApartmentBuilding has been defined with a single integer instance variable, totalUnits. Write a constructor for ApartmentBuilding that accepts three parameters: an Address and an integer to be passed up to the Building constructor, and an integer used to initialize the totalUnits instance variable.

class Building { int toatalUnit; Building(Building add, int x) { } } public class ApartmentBuilding extends Building { int toatalUnit; ApartmentBuilding(ApartmentBuilding add, int a, int b) { super(add, b); this.toatalUnit = b; } }

5 0
3 years ago
How do buffers work?
sasho [114]
A buffer is able to resist pH change because the two components (conjugate acid and conjugate base) are both present in appreciable amounts at equilibrium and are able to neutralize small amounts of other acids and bases (in the form of H3O+ and OH-) when the are added to the solution.
5 0
3 years ago
Compare and contrast between Client/Server and Peer-to-Peer networks. What are some of the business benefits of using such netwo
fgiga [73]
Client/Server and Peer-to-Peer networks are the two major network architecture models in use today. They each have advantages and disadvantages that can be used to benefit a particular outcome.

Briefly, the client/server model relates to one or many client performing relatively simple requests, which are then executed by a server. The server is performing more complex tasks, and often interacting with many clients simultaneously. Examples of client/server models include most websites, including the Brainly page you are running right this instant. Your web browser is acting as a client, and the Brainly.com website is running as a web server. It receives simple requests or information from your browser, such as clicking on a question or text typed by your keyboard, and then acts on this information by consulting a database, returning values, or returning a whole new web page to your browser. The client/server model is very powerful in business as it allows powerful and secure server-side processing and relatively simple clients. Office 365 that runs all microsoft office suites such as word and excel in a web browser on 'the cloud' is an example of a highly sophisticated client/server architecture.

By contrast, peer-to-peer networks are a distributed architecture of equals. Instead of a simple client and complex server, all clients are equals and link together to form nodes on a distributed network. There is no central control (server) and each node acts as a client and server to other nodes. This is also an extremely powerful network; as there is no central control it is difficult to shut down a peer-to-peer network. Taking out one node will not break the network in comparison to the client/server architecture where if the server goes down, services halt. Prime examples of famous peer-to-peer networks are the Bitcoin network and similar cryptographic currency networks, and music and file sharing networks such as Torrents. The torrent tracker websites are client/server however once a torrent is loaded into a torrent downloading application, the file is collectively downloaded from hundreds of 'peers' across the world as part of the torrent peer-to-peer network.


3 0
4 years ago
Other questions:
  • How many times does the following loop execute? double d; Random generator = new Random(); double x = generator.nextDouble() * 1
    14·1 answer
  • Which is better to use for cleaning electronics, Ethyl alcohol vs isopropyl alcohol?
    14·1 answer
  • 1. Why is it important to evaluate the website on which you plan to shop? (1 point)
    7·2 answers
  • Which BEST identifies the primary function of the key words above?
    5·1 answer
  • What is not true of credit scores?
    11·1 answer
  • A phonebook typically lists the name, address, and telephone number of everyone living in an area. Write code defining a structu
    15·1 answer
  • I need help in raft survival ocean nomad I was traveling and now I can't enter the island or go back home (raft). Please help me
    15·1 answer
  • Characteristics of hybrid computer​
    11·1 answer
  • Which will touch the ground first an elephant or a rock?
    9·2 answers
  • You are going to visit a national park, and have never been there before. You are using a map to try and make the distance trave
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!