これは多かれ少なかれ私の最初の Java プロジェクトです。while
ループを正しく動作させることができません。最初のオプションに入力した整数と同じ回数ループするようです。しかし、私はそれを私の2番目のものにしたいと思っています。私のコンピューターの先生はまったく役に立ちません。
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
}
}
}