我无法在java(netbeans)中循环回来 我必须创建4个类,“循环”部分是唯一未完成的部分。
package question.pkg1;
import java.util.Scanner;
public class Shape {
void secondclass(){
System.out.println("Choose the shape you want to find the Perimeter and Area of: ");
System.out.println("1. Square "
+ " 2. Rectangle ");
System.out.println("**To select sqauare, enter 1**");
System.out.println("**To select rectangle, enter 2**");
int value;
Scanner input = new Scanner(System.in);
value = input.nextInt();
if (value == 1) {
Square Squareclass = new Square();
Squareclass.thirdclass();}
else if (value == 2) {
Rectangle Rectangleclass = new Rectangle();
Rectangleclass.fourthclass();}
else{
System.out.println("**Error: Please enter a correct value!**");
}
}}
答案 0 :(得分:0)
使用do .. while循环,如:
do {
//read value
//process based on value
} while (value > 0 && value <= 2);//assuming your valid values are 1,2 and if it is let user continue further.