import java.util.Scanner;
public class Ve {
public static void main(String[]args){
int hoyde;
int linje = 0;
Scanner tast = new Scanner(System.in);
System.out.println("Hvor hoy skal din V bli?(mellom 2 og 10)");
hoyde = tast.nextInt();
tast.nextLine();
//assert (hoyde <=2 && hoyde >=10) : "hoyde må være mellom 2 og 10";
for(linje= 0; linje < hoyde;linje++) {
int start = linje;
int end = (hoyde-1)*2;
for(linje= 0;linje<=linje;linje++){
if(linje == end){
System.out.println("*");
break;
}
else if(linje == start){
System.out.print("*");
} else{
System.out.print(" ");
}
}
}
}
}
I am trying to print out a V
using *
. Somehow when I run the code, it prints out 2 single stars on the same line. I am stuck on this one, and I can't seem to find out how I am supposed to spread given information. I use the Scanner
for the input of a number for what height the V
should have.