新手学JAVA,自己写的程序,运行没结果~

rich1988 2009-10-21 09:31:25

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
...全文
385 15 打赏 收藏 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
rich1988 2009-10-24
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 yjfeng1986 的回复:]
建议不用IDE,直接在命令行下编译运行试试,刚学不要太依赖IDE了
[/Quote]


很笨的问一下,什么是IDE啊?
yjfeng1986 2009-10-22
  • 打赏
  • 举报
回复
建议不用IDE,直接在命令行下编译运行试试,刚学不要太依赖IDE了
  • 打赏
  • 举报
回复

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;

}
静水s 2009-10-22
  • 打赏
  • 举报
回复
System.in是要接受控制台的输入。LZ运行后,没在控制台输入数据吧
rich1988 2009-10-21
  • 打赏
  • 举报
回复
可以运行了,但是有问题,在自定义数组长度后,
要插入数据就只能在Array[0]中插入,后面就不可以了。
che5201314 2009-10-21
  • 打赏
  • 举报
回复



import java.util.*;
import java.util.Scanner;

public class test_hahaha
{
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 (a>-1)
{
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;
a=input.nextInt();
}


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]);

}
a=input.nextInt();
}
}
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-1]=d;
count=count+1;
a=input.nextInt();



i changed some, now the function 0 1 2 can work properly, if u like ,u can follow my way to modify ur program......
good luck man
  • 打赏
  • 举报
回复
我没有用过jcreator,不过我估计,你可能是运行了以后,看到输出的地方是一片空白就以为程序有问题,其实你这个程序一开始是要你输入东西的。

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


你可以再试下,当运行后,出现一片空白的话,你随便输入两个数,看看有什么反应。
你的程序没有问题,可以运行。
rich1988 2009-10-21
  • 打赏
  • 举报
回复
大概意思就是,一开始运行程序,
显示5项功提供用户选择。
1,显示数组中的数据
2,插入数据
3,计算数组中数据的总和
4,查找数据
5,删除数据

然后相应的用户选择,然后开始操作。
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 rich1988 的回复:]
引用 2 楼 mythofking 的回复:
LZ,下次能不能把你程序的功能说下。我运行了下,可以运行,不是你说的一片空白。
下面是部分运行结果:
4
5

1. Display the contents of the array
2. Insert a double value into the array
3. Calculate the sum total of the values in the array
4. Search the array for a particular value
5. Remove a particular double value from the array
Please choose the number:

Please type a  value to remove :


不知道是不是这样



我在Jcreator里面运行,下面的结果输出框里面就是一片空白啊,什么都没有~
你是用什么运行的?

[/Quote]
我在eclipse里面运行的
caofaping 2009-10-21
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 rich1988 的回复:]
题目是:
Write a menu-driven Java program to maintain an array of doubles.

The menu options should include:

(a) Display the contents of the array
(b) Insert a double value into the array
(c) Calculate the sum total of the values in the array

(d) Search the array for a particular value
(e) Remove a particular double value from the array


Guidelines:

Think of the array as a container of doubles. You must
decide and design the detailed workings of this container.

How will your program know when the array is empty or full?
How will your program decide where in the array to insert
a new value?
When a search value is found, how is this reported to the
user?
What must happen in order to remove a particular element
from the array?
[/Quote]

英文? 晕了!
che5201314 2009-10-21
  • 打赏
  • 举报
回复
input 4 0, 4 1
both of inputs cant make ur program get out of while loop,,,,,,,
suggestion add "break;" to stop the program
can u explain the functionality of ur program by the way?
rich1988 2009-10-21
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 mythofking 的回复:]
LZ,下次能不能把你程序的功能说下。我运行了下,可以运行,不是你说的一片空白。
下面是部分运行结果:
4
5

1. Display the contents of the array
2. Insert a double value into the array
3. Calculate the sum total of the values in the array
4. Search the array for a particular value
5. Remove a particular double value from the array
Please choose the number:

Please type a  value to remove :


不知道是不是这样
[/Quote]




我在Jcreator里面运行,下面的结果输出框里面就是一片空白啊,什么都没有~
你是用什么运行的?
rich1988 2009-10-21
  • 打赏
  • 举报
回复
题目是:
Write a menu-driven Java program to maintain an array of doubles.

The menu options should include:

(a) Display the contents of the array
(b) Insert a double value into the array
(c) Calculate the sum total of the values in the array

(d) Search the array for a particular value
(e) Remove a particular double value from the array


Guidelines:

Think of the array as a container of doubles. You must
decide and design the detailed workings of this container.

How will your program know when the array is empty or full?
How will your program decide where in the array to insert
a new value?
When a search value is found, how is this reported to the
user?
What must happen in order to remove a particular element
from the array?
  • 打赏
  • 举报
回复
LZ,下次能不能把你程序的功能说下。我运行了下,可以运行,不是你说的一片空白。
下面是部分运行结果:
4
5

1. Display the contents of the array
2. Insert a double value into the array
3. Calculate the sum total of the values in the array
4. Search the array for a particular value
5. Remove a particular double value from the array
Please choose the number:

Please type a value to remove :


不知道是不是这样
rich1988 2009-10-21
  • 打赏
  • 举报
回复
开始运行的时候,1和2 还可以显示,后面就整个程序写完,运行提示也没有错误,但是结果却是一片空白。
琢磨很久,第一次自己写的程序,也不知道哪里有问题。刚开始学JAVA,还希望高人指点。

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧