循环回java

时间:2015-09-27 09:59:24

标签: java netbeans

我无法在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!**");
}

}}

1 个答案:

答案 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.