package cs1410;
import javax.swing.*;


public class P2 {




    public static void main(String []args)
    {
         drawDiamond();    


    }


    public static void drawDiamond()
    {
        int x,y,z;
        int a=1;
        String out="\n";

        int i=Integer.parseInt(JOptionPane.showInputDialog("Enter your size"));
        if((i%2)!=0)
        {
             int in=(i/2)+(i%2);
             int bb=in-1;
             int b=bb+(bb-1);

             for(x=in;x>0;x--)
             {
                 for(y=x;y>1;y--)
                     out+=" ";

                for(z=0;z<a;z++)
                    out+="*";
                    a+=2;
                    out+="\n";
             }

             for(x=0;x<in-1;x++)
             {

                 for(y=x;y>=0;y--)
                     out+=" ";

                 for(z=0;z<b;z++)
                    out+="*";
                    b-=2;
                    out+="\n";
             }


             System.out.print(out);
             drawDiamond();
        }
        else
        {
                System.out.print("Please enter an odd number");
                drawDiamond();
        }
        }
}

    for (int i = 0; i < 20; i++)
    {
    System.out.print(" ");
    }
    for (int i = 0; i < 20; i++)
    {
    System.out.print("*");
    }
    System.out.println();
    for ( int k = 0; k < 4; k++){
    for ( int j =19 - k ; j>0; j--)
    {
    System.out.print(" ");
    }
    System.out.print("*");

    for (int i = 0; i < 18; i++)
    {
    System.out.print(" ");
    }
    System.out.println("*");
    }
    for (int i = 0; i < 15; i++)
    {
    System.out.print(" ");
    }
    for (int i = 0; i < 20; i++)
    {
    System.out.print("*");
    }
    }
    }
}

Line 66 and over is my code to print a parallelogram how do i connect this to the main method ?

Dani AI

Generated

Two quick facts that explain why your extra loops “don’t connect” to main: the parallelogram code in the paste is sitting outside the class (after its closing brace), so the compiler will complain, and your drawDiamond() currently calls itself at the end which causes repeated prompts / eventual stack overflow. Fix both by putting the drawing loops inside a method and calling that method from main.

Steps to fix

  • Move the parallelogram loop block so it’s inside the same class (but outside main) as a static helper method.
  • Call that helper from main.
  • Remove the recursive drawDiamond() call (or replace it with a controlled loop) so you don’t re-enter the method unintentionally.
  • Recompile and follow the compiler line numbers to fix any remaining brace/semicolon issues.

Minimal example (console version — not the code you posted, but a clean, compilable pattern you can adopt):

public static void printParallelogram(int width, int height, int offset) {
    for (int row = 0; row < height; row++) {
        for (int s = 0; s < offset + row; s++) System.out.print(" ");
        for (int c = 0; c < width; c++) System.out.print("*");
        System.out.println();
    }
}

public static void main(String[] args) {
    // call your existing drawDiamond() here if still needed
    printParallelogram(20, 6, 0);
}

If you actually want this inside a Swing window (tagged java:swing), implement a small JPanel and draw the shape in paintComponent(Graphics) (use drawPolygon or repeated fillRect with offsets). As hinted, keep drawing code separate from main and avoid stray braces or code outside the class. If you still get compile errors, paste the exact error messages and the file’s closing-brace region so it’s easier to spot the misplaced code.

Use it to replace the code that's already in main to print the parallelogram.
How much of this program did you write, and how much did you copy without really understanding it?
Your code looks like typical Java learner code, but the code in main for the parallelogram looks like it was coded by an amateur C coder.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.