import java.awt.*;
import java.util.Scanner;
public class question3 extends Applet {
String userStr;
public void init(){
userStr = JOptionPane.showInputDialog("Enter no of step");
}
public void paint(Graphics graphics) {
int x=70;
int y=70;
while(Integer.parseInt(userStr)<=0){
System.out.println("please enter a valid step");
Scanner nu=new Scanner(System.in);
}
for(int i=1;i<=Integer.parseInt(userStr);i++){
if (i==1){
graphics.drawLine(10,10,70,10);// horizontal line
graphics.drawLine(70,10,70,70);//vertical line
}else{
graphics.drawLine(x,y,x=70i,y);
graphics.drawLine(x,y, x,y=70i);
}
}
}
}
userStr,小于0是这个嘛?循环的条件是i=1,i<=Integer.parseInt(userStr), 你得比1大啊.还有就是你的Scanner nu 有在哪里用到嘛
while(Integer.parseInt(userStr)<=0){
System.out.println("please enter a valid step");
Scanner nu=new Scanner(System.in);
}
这段代码好好看看什么意思
Scanner nu=new Scanner(System.in);你这个只是定义了对象,并没有输入操作,你如果要有输入操作,你需要在这后面加上int age = nu.nextInt(); 或者其它数据类型,望采纳