这或多或少是我的第一个 java 项目。我无法让我的while
循环正常工作。它的循环次数似乎与我为第一个选项输入的整数一样多。但我希望它用于我的第二个。我的电脑老师一点帮助都没有。
import java.awt.*;
public class Summative extends JApplet
{
int n; //first choice variable
int t; //time variable
int integer; //integer input
int x=0; //count variable
int y=50; //test
public void init() //Initialize method
{
setSize(1000, 800); //Set size
Container c = getContentPane();
c.setBackground(Color.GREEN); //Set background
}
public void paint(Graphics g)
{
super.paint(g); //Start paint method
g.setFont(new Font("Veranda", Font.PLAIN, 20));
g.setColor(Color.BLACK);
g.drawString("Hello", 250, 25); //top display message
String number = JOptionPane.showInputDialog("Would you like a custom loop count or an infinite? 1. Custom 2. Infinite"); //test choice
n = Integer.parseInt(number);
while (n<0 || n>2);
if (n==1);
{
}
do
{
String number2 = JOptionPane.showInputDialog("How many times would you like to loop?");
integer = Integer.parseInt(number);
}while (integer<0 || integer>99999);
while (x < integer)
{
g.drawString("hi", 200, y);
x+=1;
y = y+40; //test
}
}
}