Write a program that reads an integer and displays, using asterisks a filled and hollow square, placed next to each other. for example if side length is 5 the program should display like so.This program prints a filled and hollow square.
Enter the length of a side: 5
***** *****
***** * *
***** * *
***** * *
***** *****

Answers

Answer 1
Answer:

Answer:

Here is the JAVA program.

import java.util.Scanner; //Scanner class to take input from user

 public class HollowFilledSquare {

          public static void main(String[] args) { //start of main() function body

    Scanner sc= new Scanner(System.in); // Scanner class object

          System.out.print("Enter an integer to display a filled and hollow square "); //prompts user to enter an integer

           int n = sc.nextInt(); // reads integer input from the user

          StringBuilder filled = new StringBuilder(n);

// creates objects filled and hollow of class StringBuilder

          StringBuilder hollow = new StringBuilder(n);

          for (int i = 1; i <= n; i++) { // outer loop for length of the square

              for (int j = 1; j <= n; j++) { // inner loop for width of square

                  filled.append("*"); //displays asterisks

                    if (i == 1 || i == n || j == 1 || j == n) // condition to display stars

                       {hollow.append("*");}

                   else

                     {  hollow.append(" ");  }             } // to display empty spaces

           System.out.println(filled + "   " + hollow);

// places hollow and filled squares next to each other

           filled. delete(0, filled.length());  

//removes characters from 0 to the length of filled square

           hollow. delete(0, hollow.length());      

//removes characters from 0 to the length of hollow square } }  }

Explanation:

The program first prompts the user to enter an integer. It uses outer loop for length of the square and inner loop for width of square in order to display the asterisks. append () function is used to display the sequence of asterisks. delete () function removes the  asterisks from the sequence of asterisks. String Builder is a class used for to create a string of n characters. It basically works like String but this is used to create modifiable objects.

The screen shot of the code along with the output is attached.

Answer 2
Answer:

Final answer:

A Python program can be written to read an integer that is then used to print out two squares of that side length with asterisks, one filled and one hollow. The provided Python code uses nested loops and conditionals to generate the squares accurately.

Explanation:

To complete your request, we would need to write a program to read an integer input and utilize this integer value to generate two squares with asterisks, one filled and one hollow. Here is a simple Python program:

def print_squares(n):
# Full square
for i in range(n):
 for j in range(n):
  print('*', end=' ')
 print()

# New line between squares
print()

# Hollow square
for i in range(n):
 for j in range(n):
  if i==0 or i==n-1 or j==0 or j==n-1:
   print('*', end=' ')
  else:
   print(' ', end=' ')
 print()

# Run the function
print_squares(int(input('Enter the length of a side: ')))

This program first prints a filled square and a hollow square using conditionals to distinguish between the edge and inner positions of the squares.

Learn more about Python programming here:

brainly.com/question/33469770

#SPJ3


Related Questions

What technology would you like to use or see developed that would help you be a "citizen of the world"?
If the following statement were in a C++ program, what would it do? cout >> "I love oranges and apples";
Below is a 4-bit down-counter. What is the largest number of the counter if the initial state Q3Q2Q1Q0=0011? (D3 and Q3 are MSB, and when Load = 1 and Count =1 the counter is loaded with the value D3…D0) Selected Answer: IncorrectC. 1100 Answers: CorrectA. 1111 B. 0011 C. 1100 D. 0110
Quicksort reaches the worst-case time complexity when:Partition is not implemented in placePicking the largest one of input or partitioned data as pivot valueMedian of input or partitioned data is expensive to calculateData is sorted already and always pick the median as pivotChoose the incorrect statement:When the median is always picked as pivot in input/partitioned data, then quicksort achieves the best-case time complexity.Mergesort has O(N(log(N)) time complexity for its worst case, average case and best caseInsertionsort reaches its best-case time complexity O(N log(N)) when the input data is pre-sortedQuicksort is practically fast and frequently used sorting algorithm.Choose the incorrect statement:In the lower bound analysis by using decision tree, each branch uses one comparison to narrow down possible casesIn the lower bound analysis by using decision tree, he number of required comparisons can be represented by height of decision treeA decision tree to sort N elements must have N^2 leavesO(N log(N)) lower bound means that comparison-based algorithm cannot achieve a time complexity better than O(N log(N))Choose the incorrect statement regarding time complexity of union-find operation:Inverse Ackermann function does not depend on N and is a constant factor.When we use arbitrary union and simple find for union-find operation, the worst-case time complexity is O(MN) for a sequence of M operations and N elementsUnion-by-size and Union-by-rank both improve the time complexity to O(M log(N)) for a sequence of M operations and N elementsTo finish the entire equivalence class computation algorithm, we need to go over each pair of elements, so if we use union-by-rank with path compression for find operation, then the overall time complexity is O(N^2 log*N), where log*N denotes the inverse Ackermann function.Choose the incorrect statement regarding Dijstraâs algorithmDijstraâs algorithm is a greedy algorithmDijstraâs algorithm requires to dynamically update distance/costs/weights of paths.To begin with, Dijstraâs algorithm initializes all distance as INFDijstraâs algorithm can be implemented by heaps, leading to O(|E|+|V| log(|V|)) time complexity, where, particularly, log(|V|) is due to "insert" operation in heaps.
Definition of letter in communication skills

What is the magnitude of the largest positive value you can place in a bool? a char? an int? a float?

Answers

Answer:

A bool can hold only true or false values.

A char can hold maximum 65535 characters.

An int can hold maximum positive value of 2,147,483,647.

A float can hold maximum positive value of 3.4 x 10^{38}.

Explanation:

Primitive data types in Java language can be categorized into boolean and numeric data types.

Numeric can be divided further into floating point and integral type. Floating data type includes float and double values while and integral data type which consists of char, int, short, long and byte data types.

Every data type has a range of values it can hold, i.e., every data type has a minimum and maximum predefined value which it is allowed to hold. The intermediate values fall in the range of that particular data type.

Any value outside the range of that particular data type will not compile and an error message will be displayed.

The data types commonly used in programming are boolean, char, int and float.

A boolean variable can have only two values, true or false.

A char variable can hold from 0 to 65535 characters. Maximum, 65535 characters are allowed in a character variable. At the minimum, a char variable will have no characters or it will be a null char variable, having no value.

An int variable has the range from minimum -2^{31} to maximum 2^{31} – 1. Hence, the maximum positive value an int variable can hold is (2^{31}) – 1.

A float variable can hold minimum value of 1.4 x 10^{-45} and maximum positive value of 3.4 x 10^{38}.

The above description relates to the data types and their respective range of values in Java language.

The values for boolean variable remain the same across all programming languages.

The range of values for char, int and float data types are different in other languages.

Assume you have a system where you need to maintain operability even during the failing, replacing, and rebuilding of a failed disk. Thus, the data in the failed disk must be rebuilt and written to the replacement disk while the system is in operation. Which of the RAID levels yields the least amount of interference between the rebuild and ongoing disk accesses?

Answers

Answer:

RAID level 1 fits the criteria to yield the least amount of interference between the rebuild and ongoing disk accesses.

Explanation:

RAID system can be defined as the process in which hard drives which are connected to the system are been set up in order to help speed up the performance of a computer system disk storage which is why RAID is mostly used on servers and high performance computers system . This RAID as well helps to combines multiple physical disk drive components into various logical units for the aim of increasing system performance.

Therefore RAID level 1 fits the criteria to yield the least amount of interference between the rebuild and ongoing disk accesses. This is because the level 1 of RAID copies just the data from the failed Systems disk mirror during the rebuilding period where as the other levels of RAID copies the whole lot of content of the other disks due to the fact that RAID 1 often requires at least minimum of two physical drives because data is written simultaneously to two places in which the drives are essentially mirror images of one another in which if one fails, the other one can take over and help to provide access to the data that is been stored on that drive.

Checkpoint 10.43 Write an interface named Nameable that specifies the following methods: _______{ public void setName(String n) public String getName()} Fill in the blank.

Answers

Answer:

Fill the blank with

public interface Nameable {

Explanation:

Required

Complete code segment with the interface definition

The given code segment is divided into three parts

1. The interface

2. The method that returns nothing

3. The method that returns string

The blank will be filled with the definition of the interface.

The definition is as follows:

public interface Nameable {

Analyzing the above definition

public -----> This represents the modifier

interface ------> This represents that the definition is an interface

Nameable ------> This represents the name of the interface

A babysitter charges $2.50 an hour until 9:00 PM when the rate drops to$1.75 an hour (the children are in bed). Write a program that accepts astarting time and ending time in hours and minutes and calculates the totalbabysitting bill. You may assume that the starting and ending times are ina single 24-hour period. Partial hours should be appropriately prorated.

Answers

Answer:

print("enter starting time hours")

st_hours=int(input()) #starting time hours

print("minutes")

st_minutes=int(input()) #starting time minutes

print("enter ending time hours")

et_hours=int(input()) #ending time hours

print("minutes")

et_minutes=int(input()) #ending time minutes

cost=2.50

if (st_hours<21 and et_hours>21): #if starting time is less than 21 and ending time is greater than 21

a_hours=et_hours-21

a_minutes=et_minutes #taking time after 21 from ending time ending time-21

time_minutes=60-st_minutes #converting all the time into minutes

time_hours=21-(st_hours+1)

time_hours=time_hours*60

time=time_hours+time_minutes

cost=(cost/60)*time

time=(a_hours*60)+a_minutes

cost=cost+(1.75/60)*time

print("cost=$",cost)

elif(st_hours>=21): #if starting time is greater than 21

time_hours=et_hours-(st_hours+1)

time_minutes=(60-st_minutes)+et_minutes #converting time into minutes

time=(time_hours*60)+time_minutes

cost=(1.75/60)*(time)

print("cost=$",cost)

elif(et_hours<=21): #if ending time is less than 21

time_hours=et_hours-(st_hours+1)

time_minutes=(60-st_minutes)+et_minutes

time=(time_hours*60)+time_minutes

cost=(2.50/60)*time

print("cost=$",cost)

Explanation:

This is a conditional program, the conditions applied are if and else if.

The resultant output was gotten using this three steps:

(1) If starting time is less than 21 and ending time is greater than 21

Then I converted the time into minutes before 21

ex:- 8:30

21-9= 12*60= 720 + 30 = 750

Then I calculated the bill.

750 * (2.50 / 60)

Then I converted the time after 21 and then calculated the bill and printed it.

(2)If starting time is greater than 21

Converted time into minutes and multiplied it with (1.75 / 60) to get the bill.

(3) If ending time is less than 21

Converted time into minutes and multiplied it with (2.50 / 60) to get the bill.

Please check attachment for program code screenshot.

File Letter Counter Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Use Notepad or another text editor to create a sample file that can be used to test the program.

Answers

Answer:

The solution code is written in Python.

  1. fileName = input("Enter file name: ")
  2. target = input("Enter target character: ")
  3. with open(fileName, "r")as reader:
  4.    content = reader.read()
  5.    print(content.count(target))

Explanation:

Firstly, use input() function to prompt user for a file name. (Line 1)

Next, we use input() function again to prompt user input a target character (Line 2)

Create a reader object and user read() method to copy entire texts from to the variable content (Line 4 - 5).

At last we can get the number of times the specified character appears in the file using the Python string built-in method count() (Line 6)

The function changeLocation is also called a _____.class bike:
def __init__(self,size,idNum,color ):
self.size = size
self.location = 10
self.color = color
self.idNum = idNum

def changeLocation(self,newLocation):
self.location = newLocation


manipulator

initiator

method

constructor

Answers

Answer:

The answer is a method

Explanation:

Answer:

class and self

Explanation:

class Bike:

def __init__(self, str, float):

self.color = str

self.price = float