Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is the code so far, but i cant figure out how to make the stars on the bott

ID: 3527265 • Letter: T

Question

This is the code so far, but i cant figure out how to make the stars on the bottom and and the other side it should look like this: ********* * * * * * * ********* where a is the stars on the top and bottom, while b is the height. So it changes with different inputs import java.util.Scanner; public class bajs { public static void main(String[] args){ tegnRektangel(); } public static void tegnRektangel() { int a, b; Scanner input = new Scanner(System.in); System.out.println("how long is a?"); a=input.nextInt(); System.out.println("how long is b?") ; b=input.nextInt()-1; for (int i = 1; i <= a; i++) { System.out.print("*"); } System.out.println(); for (int h=1;h <= b; h++){ System.out.println("*"); }} }

Explanation / Answer

For the loop part of it you can set it up like so:

for(row = 1; row <= b; row++){
for(column = 1; column <= a; column++) {

if(row == 1 || row == b)
System.out.print("*");
else if(column == 1 || column == a)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}

This way if its on the top row and the last row it'll only print out "*" throughout the column. And for all the other rows it'll follow the column if statement printing "*" at the beginning followed by spaces and then another "*" at the end.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote