Question

3.a.Imagine you have a box of asterisks (*). Write a psuedocode that will instruct a person...

3.a.Imagine you have a box of asterisks (*). Write a psuedocode that will instruct a person to stack fifteen *s into the arrangement below. Write the solution in a way that can be generalized easily to larger arrangements.

*
**
***
****
*****

3.b Imagine you have a box of asterisks (*). Write a psuedocode that will instruct a person to stack nine *s into the arrangement below. Write the solution in a way that can be generalized easily to larger arrangements.

*
***
*****

3.c. It’s ok to make errors. In fact, the more errors you make, the quicker you will become an expert Java programmer. Each error can teach you an important lesson. So, let’s make a few errors by experimenting with the HelloWorldClasswork1 program.

a) Try deleting the only semicolon. What happens when you compile? Fix the error.

b) Try deleting the left brace under the main method and compiling your program. What happens? Fix the error.

c) Delete the first left brace in the program. What happens when you compile? Fix the program.

d) Change main to Main. Does the program compile? What is the problem

3.d. Assume you are a bank manager and you want to teach the tellers in the bank how to count the paper currency in their teller drawers. Write pseudocode for a method of counting the money.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

3.a)

Java code:

import java.util.*;
import java.lang.*;
import java.io.*;


class star
{
   public static void main (String[] args)
   {
       int k,j,n;
       System.out.println("Please enter how many stars do you have?");
       Scanner sc = new Scanner(System.in);
       n= sc.nextInt();
j=1;
  
while(j<=n)
{
for(k=1;k<=j;k++)
{
System.out.print("*");
}
System.out.println("\n");
n=n-j;
j++;
  
}
   }
}
Output:

Please enter how many stars do you have?

15
*

**

***

****

*****

b)

import java.util.*;
import java.lang.*;
import java.io.*;


class star
{
   public static void main (String[] args)
   {
       int k,j,n;
       System.out.println("Please enter how many stars do you have?");
       Scanner sc = new Scanner(System.in);
       n= sc.nextInt();
j=1;
  
while(j<=n)
{
for(k=1;k<=j;k++)
{
System.out.print("*");
  
}
System.out.println("\n");
n=n-j;
j=j+2;
  
}
   }
}
Output:

Please enter how many stars do you have?

9
*

***

*****

Add a comment
Know the answer?
Add Answer to:
3.a.Imagine you have a box of asterisks (*). Write a psuedocode that will instruct a person...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Prelab Exercises Your task is to write a Java program that will print out the following...

    Prelab Exercises Your task is to write a Java program that will print out the following message (including the row of equal marks): Computer Science, Yes!!!! ========================= An outline of the program is below. Complete it as follows: a. In the documentation at the top, fill in the name of the file the program would be saved in and a brief description of what the program does. b. Add the code for the main method to do the printing. //...

  • Lab 3 Step One First, create an empty directory for lab3. There is no starter code for this lab. You will be throwing an...

    Lab 3 Step One First, create an empty directory for lab3. There is no starter code for this lab. You will be throwing and catching exceptions in this exercise. Create a file called RuntimeException.h and put the following code in it. #include <string> class RuntimeException { private: string errorMsg; public: RuntimeException(const string& err) { errorMsg = err; } string getMessage() const { return errorMsg; } } Step Two In a new .cpp file in your directory, write a main function...

  • Assignment Overview In Part 1 of this assignment, you will write a main program and several...

    Assignment Overview In Part 1 of this assignment, you will write a main program and several classes to create and print a small database of baseball player data. The assignment has been split into two parts to encourage you to code your program in an incremental fashion, a technique that will be increasingly important as the semester goes on. Purpose This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of...

  • Lab 3 – Array-Based Stack and Queue Overview In this assignment, you will be implementing your...

    Lab 3 – Array-Based Stack and Queue Overview In this assignment, you will be implementing your own Array-Based Stack (ABS) and Array-Based Queue (ABQ). A stack is a linear data structure which follows the Last-In, First-Out (LIFO) property. LIFO means that the data most recently added is the first data to be removed. (Imagine a stack of books, or a stack of papers on a desk—the first one to be removed is the last one placed on top.) A queue...

  • I have updated my previously posted C++ question to ensure that I have included all of...

    I have updated my previously posted C++ question to ensure that I have included all of the necessary documentation in order to complete Part 2 - Bank Account of the assigned lab in its entirety. Please note that the lab below is somewhat lengthy, and I do not expect you to answer each question! If coding the full lab is too much to ask, please focus soley on Part 2 of the lab, titled Bank Account and the subsections that...

  • How do i write the pseudocode for this java code? First, write out pseudocode, and then create a program to help you by accomplishing the following tasks: :  Use command line interface to ask the use...

    How do i write the pseudocode for this java code? First, write out pseudocode, and then create a program to help you by accomplishing the following tasks: :  Use command line interface to ask the user to input the following. ○ How many apples are on hand ○ How many apples should be in stock ○ How many oranges are on hand ○ How many oranges should be in stock  Perform an operation to determine how many of...

  • Use C++ For this week’s lab you will write a program to read a data file...

    Use C++ For this week’s lab you will write a program to read a data file containing numerical values, one per line. The program should compute average of the numbers and also find the smallest and the largest value in the file. You may assume that the data file will have EXACTLY 100 integer values in it. Process all the values out of the data file. Show the average, smallest, largest, and the name of the data file in the...

  • #include<stdio.h> #include<stdlib.h> #include <time.h> int main() { /* first you have to let the computer generate...

    #include<stdio.h> #include<stdlib.h> #include <time.h> int main() { /* first you have to let the computer generate a random number. Then it has to declare how many tries the user has for the game loop. we then need the player to enter their guess. After every guess we have to give an output of how many numbers they have in the right location and how many they have the right number. The player will keep guessing until their 10 tries are...

  • please use python and provide run result, thank you! click on pic to make it bigger...

    please use python and provide run result, thank you! click on pic to make it bigger For this assignment you will have to investigate the use of the Python random library's random generator function, random.randrange(stop), randrange produces a random integer in the range of 0 to stop-1. You will need to import random at the top of your program. You can find this in the text or using the online resources given in the lectures A Slot Machine Simulation Understand...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT