0
這或多或少是我的第一個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
}
}
}
感謝您在分號上的提示,幫助清理了代碼。並且@seth感謝那裏的修復,修復了它。擰上變量:P – Nadim