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

I have most of the work done, but i need to be able to input the size of the hol

ID: 3757678 • Letter: I

Question

I have most of the work done, but i need to be able to input the size of the hollow diamond and i cannot figure out how. So my question is, what is the right way to code in (using my existing code) the input size of the diamond? Example would be:

Input design: +

Input size: 5

+

+ +

+ +

+ +

+

Heres what i have so far:

import java.util.Scanner;

public class ExtraCredit {

   public static void main(String[] args) {

       Scanner keyboard = new Scanner(System.in);

       System.out.println("Input the design character: ");

       String stringDiamond = keyboard.nextLine();

   System.out.println("Input the size: ");

   int inputSize = keyboard.nextInt();

       int a = 0;

   for(int i = 5;i >= 1;i--){

   for(int j = 1;j <= 9;j++){

   if(j == i || (10 - i) == j)

   {

   System.out.print(stringDiamond.charAt(a));

   }

   else {

   System.out.print(' ');

   }

   }

   System.out.println();

   }

   for(int i =2;i <= 5;i++){

   for(int j = 1;j <= 9;j++){

   if(j == i || (10 - i) == j){

   System.out.print(stringDiamond.charAt(a));   

   }

   else

   {

   System.out.print(' ');

   }

   }

   System.out.println();

   }

   }}

Explanation / Answer

i tnink you wnat enter the input size from keyboard then this program helps to you print pluses in dimond shape.

the rquired size you can enter.

import java.util.Scanner;


public class PlusPattern
{
public static void main(String[] args)
{
System.out.print("Enter how many roes you required : ");
Scanner in = new Scanner(System.in);
int num=in.nextInt();
for(int i=1;i<=num;i++)
{
for(int j=num;j>=i;j--)
{
System.out.print(" ");
}
for(int k=1;k<=i;k++)
{
System.out.print(" +");
}
System.out.print(" ");
}   
for(int i=1;i<=num;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(" ");
}
for(int k=num;k>=i;k--)
{
System.out.print(" +");
}
System.out.print(" ");
}
}
  
}

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