package myMenuProject;import java.util.*;
import java.util.Scanner;
public class menu
{
public static void main(String args[])
{
Scanner input;
input=new Scanner(System.in);
double Array[],e;
int count;//length of array
count = input.nextInt();
Array=new double[count];
boolean finish=false;
int d=0;
int a;
a=input.nextInt();//takes in the option chosen from the menu
while (!finish)
{
System.out.println("\n1. Display the contents of the array \n"
+"2. Insert a double value into the array\n"
+"3. Calculate the sum total of the values in the array \n"
+"4. Search the array for a particular value\n"
+"5. Remove a particular double value from the array\n"
+"Please choose the number:");
if (a==1)
{
if (count==0)
{
System.out.println("Empty array!\n");
}
else
{
for(int b=0;b<count;b++)
{
System.out.println(Array[b]);
}
}
}
if(a==2)
{
System.out.println("(1).define the length of the array:\n"
);
System.out.println("Please input the length of array:");
count=input.nextInt(); //length of array
Array=new double[count];
System.out.println("(2).Insert a double value into the array\n");
System.out.println("Please fill in:");
System.out.print("Array[" + d +"] = ");
Array[d]=input.nextDouble();
}
if(a==3)
{
double total =0.0;
for(;d<count;d++)
{ total = total + Array[d];
d++;
}
System.out.println("total is :"+ total +"\n");
}
if(a==4)
{
System.out.print("\nPlease input a double value to search for: ");
e =input.nextDouble();
while (d != (count-1) && Array[d] != e)
{
d++;
}
if (Array[d] == e) {System.out.print("\n" +e+ " was found in Array index " +d+"\n");}
else if (d == (count-1)) {System.out.print("\n" +e+ " was not found in the array\n");}
}
if(a==5)
{
System.out.print("\nPlease input a double value to remove from the array: ");
e =input.nextDouble();
while (d != (count-1) && Array[d] != e)
{
d++;
}
if (Array[d] == e)
{ Array[d] = 0.0;
System.out.print("\n" +e+ " was found in Array index " +d+ " and has been removed\n");}
else if (d == (count-1)) {System.out.print("\n"+e+" was not found in the array\n");}
}
}
System.out.println("You can only choose the number from the menu!") ;//if n==0 or n>5
}//main
}//class
在JCreator中运行,没有错误,但是就是运行不出结果,什么都没显示。
第一写的程序,检查了半天也看不出错,还请大家帮帮忙啊~
import java.util.Scanner;
public class menu
{
public static void main(String args[])
{
Scanner input;
input=new Scanner(System.in);
double Array[],e;
int count;//length of array
count = input.nextInt();
Array=new double[count];
boolean finish=false;
int d=0;
int a;
a=input.nextInt();//takes in the option chosen from the menu
while (!finish)
{
System.out.println("\n1. Display the contents of the array \n"
+"2. Insert a double value into the array\n"
+"3. Calculate the sum total of the values in the array \n"
+"4. Search the array for a particular value\n"
+"5. Remove a particular double value from the array\n"
+"Please choose the number:");
if (a==1)
{
if (count==0)
{
System.out.println("Empty array!\n");
}
else
{
for(int b=0;b<count;b++)
{
System.out.println(Array[b]);
}
}
}
if(a==2)
{
System.out.println("(1).define the length of the array:\n"
);
System.out.println("Please input the length of array:");
count=input.nextInt(); //length of array
Array=new double[count];
System.out.println("(2).Insert a double value into the array\n");
System.out.println("Please fill in:");
System.out.print("Array[" + d +"] = ");
Array[d]=input.nextDouble();
}
if(a==3)
{
double total =0.0;
for(;d<count;d++)
{ total = total + Array[d];
d++;
}
System.out.println("total is :"+ total +"\n");
}
if(a==4)
{
System.out.print("\nPlease input a double value to search for: ");
e =input.nextDouble();
while (d != (count-1) && Array[d] != e)
{
d++;
}
if (Array[d] == e) {System.out.print("\n" +e+ " was found in Array index " +d+"\n");}
else if (d == (count-1)) {System.out.print("\n" +e+ " was not found in the array\n");}
}
if(a==5)
{
System.out.print("\nPlease input a double value to remove from the array: ");
e =input.nextDouble();
while (d != (count-1) && Array[d] != e)
{
d++;
}
if (Array[d] == e)
{ Array[d] = 0.0;
System.out.print("\n" +e+ " was found in Array index " +d+ " and has been removed\n");}
else if (d == (count-1)) {System.out.print("\n"+e+" was not found in the array\n");}
}
}
System.out.println("You can only choose the number from the menu!") ;//if n==0 or n>5
}//main
}//class
在JCreator中运行,没有错误,但是就是运行不出结果,什么都没显示。
第一写的程序,检查了半天也看不出错,还请大家帮帮忙啊~
import java.util.*;
public class Menu {
public static void main(String args[]){ Scanner input = new Scanner(System.in);
double Array[],e;
int count;//length of array
count = input.nextInt();
Array=new double[count];
boolean finish=false;
int d=0;
int a;
a=input.nextInt();//takes in the option chosen from the menu
while (!finish){
System.out.println("\n1. Display the contents of the array \n"
+"2. Insert a double value into the array\n"
+"3. Calculate the sum total of the values in the array \n"
+"4. Search the array for a particular value\n"
+"5. Remove a particular double value from the array\n"
+"Please choose the number:");
if (a==1){
if (count==0){
System.out.println("Empty array!\n");
}else{
for(int b=0;b <count;b++){
System.out.println(Array[b]);
}
}
}
if(a==2){
System.out.println("(1).define the length of the array:\n");
System.out.println("Please input the length of array:");
count=input.nextInt(); //length of array
Array=new double[count];
System.out.println("(2).Insert a double value into the array\n");
System.out.println("Please fill in:");
System.out.print("Array[" + d +"] = ");
Array[d]=input.nextDouble();
}
if(a==3){
double total =0.0;
for(;d <count;d++){
total = total + Array[d];
d++;
}
System.out.println("total is :"+ total +"\n");
}
if(a==4){
System.out.print("\nPlease input a double value to search for: ");
e =input.nextDouble();
while (d != (count-1) && Array[d] != e){
d++;
}
if (Array[d] == e){
System.out.print("\n" +e+ " was found in Array index " +d+"\n");
}else if(d == (count-1)){
System.out.print("\n" +e+ " was not found in the array\n");
}
}
if(a==5){
System.out.print("\nPlease input a double value to remove from the array: ");
e =input.nextDouble();
while (d != (count-1) && Array[d] != e){
d++;
}
if (Array[d] == e){
Array[d] = 0.0;
System.out.print("\n" +e+ " was found in Array index " +d+ " and has been removed\n");
}else if (d == (count-1)){
System.out.print("\n"+e+" was not found in the array\n");
}
}
}
System.out.println("You can only choose the number from the menu!") ;//if n==0 or n>5
}
}
没看出来那个while循环的结束条件在哪里做了设置,貌似那个finish一直是false,所以一直在输出
楼主,下次问问题请简要说明下你发的程序所要实现的功能