我不明白我应该如何让这个程序停止。基本上它想要我做的是当我输入 -1 时程序关闭。我只是不知道怎么做。哦!“sida”在瑞典语中的意思是边。不知道有没有用!在这里得到你们的帮助会很棒!
import java.util.Scanner;
public class triangle
{
//Triangle is going up
public static void triangelUpp(int sida)
{
for(int i = 0; i <= sida; i++)
{
for(int j = 1; j <= i; j++)
System.out.print("*");
System.out.println();
}
}
//Triangle going down
public static void triangelNed(int sida)
{
for(int i = 0; i <= sida; i++)
{
for(int j = 1; j <= sida - i; j++)
System.out.print("*");
System.out.println();
}
}
public static void main(String[] args)
{
//Variables
Scanner keyboard = new Scanner(System.in);
int vinkel = 0;
int sida = 0;
//Rules
while(sida !=-1)
{
if(vinkel == 0)
triangelNed(sida);
else if(vinkel == 1)
triangelUpp(sida);
System.out.println("Write the length of the triangle and end with -1");
sida = keyboard.nextInt();
System.out.println("Is the angle going to be up(1) or down?(0)");
vinkel = keyboard.nextInt();
}
}
}