Your code is hard to read. i, I, j, J, k, K, num, num1, etc... they don't make much sense, do they? You should name variables in a way that they convey some meaning. You'll look at your code months later and even you will forget what they mean. You should use variable names like row or column, etc.
Let me share my solution to the problem so you can take away anything from it that is useful for you:
import java.util.Scanner;
public class Main
{
private static final char FULL = '*';
private static final char EMPTY = ' ';
public static void main(String args[])
{
System.out.print("Height? ");
int height = new Scanner(System.in).nextInt();
int width = height + 1; // +1 to make it look symmetric
// Let's divide the star into 4 equal segments --> Hence the star looks best if height is a whole multiple of 4
int top = 0;
int middleTop = height / 4;
int middleBottom = height / 2;
int bottom = height * 3 / 4;
// Let's start rendering every row from 0 to height
int row = 0;
//
// top
//
int start = width / 2;
int end = start;
while (row < middleTop)
{
for (int column = 0; column < width; column++)
System.out.print((start <= column && column <= end) ? FULL : EMPTY);
start--;
end++;
System.out.println();
row++;
}
//
// middle top
//
start = 0;
end = width - 1;
while (row < middleBottom)
{
for (int column = 0; column < width; column++)
System.out.print((start <= column && column <= end) ? FULL : EMPTY);
start++;
end--;
System.out.println();
row++;
}
start--;
end++;
//
// middle bottom
//
while (row < bottom)
{
for (int column = 0; column < width; column++)
System.out.print((start <= column && column <= end) ? FULL : EMPTY);
start--;
end++;
System.out.println();
row++;
}
//
// bottom
//
int triangleWidth = height - bottom - 1;
start = width / 2 - triangleWidth;
end = width / 2 + triangleWidth;
while (row < height)
{
for (int column = 0; column < width; column++)
System.out.print((start <= column && column <= end) ? FULL : EMPTY);
start++;
end--;
System.out.println();
row++;
}
}
}
Notes
A Simple Solution
The above is a very crude solution to cover the entire area of David's Star. As comments say, it looks best if the height of the David's Star is a whole multiple of 4. It works though and should be easy to understand.
A Better Solution
A more flexible solution would be to write your own ASCII wireframe renderer. Similar to a graphics renderer, but you only do it via characters. You could define points ((x, y) coordinates) and connect them with a line. The renderer would go one by one across all the characters per row and column and check if they align with the line. If they do, put a mark there, otherwise, leave it empty.
This way, you could draw your David's Star (or any 2D wireframe shape) in a few lines of code:
import java.util.Scanner;
public class Main
{
private static final char FULL = '#';
private static final char EMPTY = ' ';
private static final int preferredHeight = 14;
private static final int preferredWidth = 12;
public static void main(String args[])
{
System.out.print("Height? ");
int height = new Scanner(System.in).nextInt();
float scaleY = (float)height / preferredHeight;
float scaleX = scaleY;
Renderer renderer = new Renderer();
renderer.Add(new Triangle(new Point(0, 4), new Point(12, 4), new Point(6, 14)).Scale(scaleX, scaleY));
renderer.Add(new Triangle(new Point(0, 10), new Point(12, 10), new Point(6, 0)).Scale(scaleX, scaleY));
renderer.Render(new Point(0, 0), new Point(preferredWidth, preferredHeight).Scale(scaleX, scaleY), FULL, EMPTY);
}
}