62,621
社区成员
发帖
与我相关
我的任务
分享
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==0)
{
System.out.println("You can only choose the number from the menu!") ;//if n==0 or n>5 finish=true;
}
else 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]);
}
}
}
else 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();
Array[count]=d;
count=count+1;
}
else if(a==3)
{
double total =0.0;
while(d<count)
{ total= total + Array[d];
d++;
}
System.out.println("total is :"+ total +"\n");
}
else if(a==4)
{
System.out.print("\nPlease type value to search : ");
e =input.nextDouble();
while ( Array[d] != e)
{
d++;
}
if (Array[d] == e)
{
System.out.print("\n" +e+ " was found in Array " +d+"\n");
}
}
else if(a==5)
{
System.out.print("\nPlease type a value to remove : ");
e =input.nextDouble();
while ( Array[d] != e)
{
d++;
}
Array[d] = 0.0;
if (Array[d] == e)
{
System.out.print("\n" +e+ " was found in Array " +d+ " and has been deletedd\n");
}
}
}
}//main
}//class
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();
Array[count]=d;
count=count+1;
}
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