I've just given this as a response to an absolute beginner on SO, and I'm wondering how terrible it is.
Output for an odd number of lines:
>
>>>
>>>>>
>>>
>
Output for an even number of lines:
>
>>>
>>>>>
>>>>>
>>>
>
The code:
int lines = 7;
int half = lines/2;
String carat = ">";
int i;
//better to declare first or does it not matter?
if(lines%2==0){boolean even = true;}
else{boolean even = false;}
for(i=1;i<=lines;i++){
System.out.println(carat + "\n");
if(i==half && even){System.out.println(carat+"\n");}
if(((i>=half && even) || (i>=half+1)) && i!=lines){
carat = carat.substring(0,carat.length()-2);
}else{
carat = carat + ">>";
}
}
This code just seems so ugly, not considering the fact that there is no method that takes number of lines and that it is abusing integer rounding.