Write a Java program which implements both the while and for loop, as needed, to draw the illustrations given below.
Shape 1
123456789
12345678
1234567
123456
12345
1234
123
12
1
Shape 2
************* ************* ************* ************* *************
Shape 3
============
* *
* *
* *
* *
* *
============
Hint:
To draw the shapes above, you can use nested for loops to
accomplish the task. The outer for loop iterates on each row, and
the inner for loop iterates on each column of current row.
Shape 1 has 9 rows and column is decreasing on each row.
for (int row=0; row <rowSize; row++) //iterate for each row
{
for (int col=1; col<=rowSize-row; col++) //for each column on current row
{
//display col number with a space
}
// display a new line
}
Shape 2 has 5 rows, 13 columns.
for (int row=0; row <rowSize; row++) //iterate for each row
{
for (int col=0; col<colSize; col++) //for each column on current row
{
//display *
}
// display a new line
}
class Shapes
{
public static void main(String[] args)
{
System.out.println("Shape 1 Task");
int rowSize=9,row,col;
for(row=0;row<rowSize;row++)
{
for(col=1;col<=rowSize-row;col++)
{
System.out.print(col);
}
System.out.println();
}
System.out.println("Shape 2 Task");
int colSize=13;
rowSize=5;
for (row=0; row <rowSize; row++) //iterate for each row
{
for (col=0; col<colSize; col++) //for each column on current
row
{
System.out.print("*");
}
System.out.println();
}
System.out.println("Shape 3 Task");
rowSize=7;
colSize=12;
for (row=0; row <rowSize; row++) //iterate for each row
{
for (col=0; col<colSize; col++) //for each column on current
row
{
if(row==0 || row==6)
System.out.print("=");
else if(col==0 || col==10)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
}
}
Output

Write a Java program which implements both the while and for loop, as needed, to draw...
Iterating over a 2D array If we want to visit or process every element of a 2D array, we need a nested for loop to do it. Generally, when you iterate over a 2D array, you want to do it in row major order, because this is more memory efficient. The reason why is that adjacent elements in a row are stored contiguously (one after another) in memory. Another reason, for an English speaker, is that this is the same...
C++ any help is appreciated Program Pattern#2: Write a program that uses nested loop or for statements to display Pattern A below, followed by an empty line and then another set of loops that displays Pattern B. Once again no setw implementation is allowed here but you must use nested loop or for statements with proper indentation to generate these patterns. Use meaningful variable identifier names, good prompting messages and appropriate comments for each loop segment as well as other...
I need a basic program in C to modify my program with
the following instructions:
Create a program in C that will:
Add an option 4 to your menu for "Play Bingo"
-read in a bingo call (e,g, B6, I17, G57, G65)
-checks to see if the bingo call read in is valid (i.e., G65 is
not valid)
-marks all the boards that have the bingo call
-checks to see if there is a winner, for our purposes winning
means...
Java 1. Write a getCount method in the IntArrayWorker class that returns the count of the number of times a passed integer value is found in the matrix. There is already a method to test this in IntArrayWorkerTester. Just uncomment the method testGetCount() and the call to it in the main method of IntArrayWorkerTester. 2. Write a getLargest method in the IntArrayWorker class that returns the largest value in the matrix. There is already a method to test this in...
Instructions Write a program in Java that implements the A* algorithm to find a path from any two given nodes. Problem Overview & Algorithm Description In a fully-observable environment where there are both pathable and blocked nodes, an agent must find a good path from their starting node to the goal node. The agent must use the A* algorithm to determine its path. For this program, you must use the Manhattan method for calculating the heuristic. Remember: your heuristic function...
This program is in C++ which reserves flight seats. It uses a file imported to get the seat chart called "chartIn.txt" which looks like this 1 A B C D E F 2 A B C D E F It continues until row 10. Sorry unable to provide the chartIn.txt file. I am having issues with function displaySeats, it displays then but when it comes to 10 the row looks like this 1 0 A B C D E ,...
Hi I need help with a java program that I need to create a Airline Reservation System I already finish it but it doesnt work can someone please help me I would be delighted it doesnt show the available seats when running the program and I need it to run until someone says no for booking a seat and if they want to cancel a seat it should ask the user to cancel a seat or continue booking also it...
Java use for loop (nested for loop) if/else possible
on blue J.
(row *col)%2 for 0's and 1's.
Write a program to generate the below table: . The table should be able to vary in size based on a class constant called SIZE; minimum of 1, maximum of 9. . The O's and 1's can and should be generated by evaluating a mathematical expression using the row and column numbers Think about the operators: +-* / % . The output...
Can someone finish this class for me? There are comment instructions with what to do in the methods already. public class ArrayDemo { public void demonstrateTask1(){ System.out.println("Demonstrate Task 1"); int[] numbers = null; // note that numbers references nothing (null) initially ...
Step 1: Getting Started Create a new .java file named Lab12.java. At the beginning of this file, include your assignment documentation code block. After the documentation block, you will need several import statements. import java.util.Scanner; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; Next, declare the Lab12 class and define the main function. public class Lab12 { public static void main (String [] args) { Step 2: Declaring Variables For this section of the lab, you will need to declare...