So I am a newbie obviously, This was part of a small assignment I had to do for Uni, and it works alright. It just reads a number from the console and then outputs the Greek letter Φ (sort of). Sure it could use some outofbound
exceptions etc, but my question is this: My code overall (not just in this example) seems a little bit messy to me after I read it. My variable names are messy and I need to work on that and perhaps a few methods here and there, even though this assignment wasn't about methods but rather a warm up of basic Java syntax.
I want to write better code, but I don't know where to start.Should I use more variables? I am not greatly familiar with JavaDocs yet, should they be used for small programs as well? How much procedures is too much? Should I break it down more? I feel like my "algorithm" even though it works it could be better. Online tutorials usually teach syntax but I want to make my code as good and readable as possible.
import java.util.*;
public class A11{
public static void main(String args[]){
/*Declare Num, then parse the number from the command line
into the variable,and finaly inform the user before moving on*/
int temp=0;
int num =0;
num=Integer.parseInt(args[0]);
System.out.println();
System.out.println("Number = " + num);
temp=num/2;
/*Prints the first Line (approp spaces and a Star)*/
if(num%2==0){
temp-=1;
}
for(int v=0;v<=temp;v++){
System.out.print(" ");
}
System.out.println("*");
/*Print the remaining Shape according to the input*/
/* Loop algorithm to calculate and output the appropreate amount of
characters required to form the TOP half of the shape */
if(num%2==0){temp=num/2-1;}
for(int i=1;i<=temp;i++){
for(int j=0;j<temp-i;j++){
System.out.print(" ");
}
System.out.print("*");
for(int k=0;k<2;k++){
for(int j=0;j<i;j++){
System.out.print(" ");
}
System.out.print("*");
}
System.out.println();
}
/*Bottom half - if Num is an odd number flip the top shape but loose one line*/
int space=temp;
if(num%2==1){
temp-=1;
}
for(int i=temp;i>=1;i--){
for(int j=space-i;j>0;j--){
System.out.print(" ");
}
System.out.print("*");
for(int k=0;k<2;k++){
for(int j=0;j<i;j++){
System.out.print(" ");
}
System.out.print("*");
}
System.out.println();
}
temp=num/2;
/*Prints the last line and Star*/
if(num%2==0){
temp-=1;
}
for(int v=0;v<=temp;v++){
System.out.print(" ");
}
System.out.println("*");
}
}