## 在switch-case语句之后，do-while循环不会循环内容来源于 Stack Overflow，并遵循CC BY-SA 3.0许可协议进行翻译与使用

• 回答 (2)
• 关注 (0)
• 查看 (97)

``````  int whichMethod;
do{
whichMethod = scan.nextInt();
switch(whichMethod){
case 1:
System.out.println("Enter x and y values:");
x = scan.nextDouble();
y = scan.nextDouble();
Point p = new Point(x, y);
break;
case 2:
System.out.println("Enter x and y values:");
x = scan.nextDouble();
y = scan.nextDouble();
Point case2p = new Point(x, y);
case2p.flip();
System.out.println("Flipped Coordinates" + case2p);
break;
case 3:
System.out.println("Enter x and y values:");
x = scan.nextDouble();
y = scan.nextDouble();
Point case3p = new Point(x, y);

System.out.println("Enter x and y values for the 2nd Point: ");
x = scan.nextDouble();
y = scan.nextDouble();
Point case3p2 = new Point(x, y);
System.out.println("Manhattan Distance:"+
case3p.manhattanDistance(case3p2));
break;
case 4:
System.out.println("Enter x and y values:");
x = scan.nextDouble();
y = scan.nextDouble();
Point case4p = new Point(x, y);

System.out.println("Enter x and y values for the 2nd Point: ");
x = scan.nextDouble();
y = scan.nextDouble();
Point case4p2 = new Point(x, y);
System.out.println("Are they Vertical?: " + case4p.isVertical(case4p2));
break;
case 5:
System.out.println("Enter x and y values:");
x = scan.nextDouble();
y = scan.nextDouble();
Point case5p = new Point(x, y);

System.out.println("Enter x and y values for the 2nd Point:");
x = scan.nextDouble();
y = scan.nextDouble();
Point case5p2 = new Point(x, y);
System.out.println("Slope is: " + case5p.slope(case5p2));
break;
case 6:
System.out.println("Enter x and y values:");
x = scan.nextDouble();
y = scan.nextDouble();
Point case6p = new Point(x, y);

System.out.println("Enter x and y values for the 2nd Point:");
x = scan.nextDouble();
y = scan.nextDouble();
Point case6p2 = new Point(x, y);

System.out.println("Enter x and y values for the 3rd Point:");
x = scan.nextDouble();
y = scan.nextDouble();
Point case6p3 = new Point(x, y);
System.out.println("Are they Collinear?: "+ case6p.isCollinear(case6p2, case6p3));
break;
default:
System.out.println("This isn't one of the methods available.");
System.out.println("Please enter a number between 1 and 6");
}

} while((whichMethod >= 1) && (whichMethod <= 6));
``````

### 2 个回答

``````Set<Integer> validInputs = new Set();