0
我有這個項目,我必須設置一個菜單驅動的程序(在eclipse中的java)。它不一定是一個GUI,它可以用一系列system.out.println完成,但這是我遇到問題的地方。除了設置部分外,我還完成了大部分代碼。每個部分必須有一個退出選項,程序本身有3個部分。第一種是從用戶中取1到100的數字,其次是從小到大排列,第三是數字是否可以形成三角形的邊。我已經完成了第2步和第3步的代碼,但無法使打開的菜單部分正常工作。它需要是一些東西,當用戶輸入1時,它選擇1,2,2和3,但選項2和3不能工作,除非選項1已經完成。這就是我迄今爲止所做的,我怎樣才能讓剩下的工作?麻煩設置菜單程序
import java.util.*;
import java.io.*;
public class Projcet {
static Scanner console = new Scanner(System.in);
public static void main(String[] args) {
// TODO Auto-generated method stub
int A;
int B;
int C;
int num1;
int num2;
int num3;
int opt2;
int opt3;
int Exit;
System.out.println("This program is used to determine if three integers between 1-100 can form the sides of a triangle");
System.out.println("Enter your first number between 1 and 100");
num1= console.nextInt();
System.out.println("Enter your second number between 1 and 100");
num2 = console.nextInt();
System.out.println("Enter your third number between 1 and 100");
num3 = console.nextInt();
System.out.println("Select your next step");
System.out.println("Do not select step 3 if step 2 is not completed");
System.out.println("Exit");
System.out.println("opt2-Order your number in ascending order");
System.out.println("opt3-Determine if the three inputs form a triangle");
opt3 = console.nextInt();
opt2 = console.nextInt();
Exit =
opt2 =
public static void int(opt2)
{
import javax.swing.JOptionPane;
import java.util.*;
public class projecttest
{ public static void main(String[] args)
{
int num, i, j, temp;
Scanner input = new Scanner(System.in);
System.out.println("Enter the number of integers to sort:");
num = input.nextInt();
int array[] = new int[num];
System.out.println("Enter " + num + " integers: ");
for (i = 0; i < num; i++)
array[i] = input.nextInt();
for (i = 0; i < (num - 1); i++) {
for (j = 0; j < num - i - 1; j++) {
if (array[j] > array[j+1])
{
temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
}
}
}
System.out.println("Sorted list of integers:");
for (i = 0; i < num; i++)
System.out.println(array[i]);
public staic void int(opt3)
{
import java.util.*;
public class triangle {
static Scanner console = new Scanner(System.in);
public static void main(String[] args) {
// TODO Auto-generated method stub
int a;
int b;
int c;
System.out.println("Enter a number for a");
System.out.println("Enter a number for b");
System.out.println("Enter a number for c");
a = console.nextInt();
b = console.nextInt();
c = console.nextInt();
if (a+b>c && a+c>b && b+c>a)
{
System.out.print("TRIANGLE");
}
else
{
System.out.print("NO TRIANGLE");
}
}
}