Topic: 高手们 谁可以告诉我这个程序哪里错那啊~?

  Print this page

1.高手们 谁可以告诉我这个程序哪里错那啊~? Copy to clipboard
Posted by: adamliu84
Posted on: 2005-01-14 00:06

public class AreaOfSchoolNew2
{
public static void main(String[] args)
   {  
     double i,s,num;
     int m,j;
     System.out.println("please input How many triangles in this Area:");
int n=MyInput.readInt();
      double [][] a = new double [n][3];
System.out.println("please ENTER the three length of the triangle's lines:");
for (m=0;m<n;m++)
     {
     for (j=0; j<a[0].length; j++)
     a [m][j]=MyInput.readDouble();
     System.out.println("please ENTER the other three length of the triangle's lines:");
     }
double total = num (double[][] a, int n)
         if (total<=0)
         System.out.println("The ENTER numbers are wrong!!!");
        
     System.out.println("The campus's area is "+total+"square meters");
  }
public static double num (double[][] site, int n ){
  int i;
double s, num;
for (i=0;i<n;i++)
     {
    
     s=0.5*(site[i][0]+site[i][1]+site[i][2]);

     num=Math.sqrt(s*(s-site[i][0])*(s-site[i][1])*(s-site[i][2]));
     }

     for (i=0; i<n; i++)
       {
     num=+num;
     num=num*20000*20000/10000;
         }

    return num ;  
  }
               }

2.Re:高手们 谁可以告诉我这个程序哪里错那啊~? [Re: adamliu84] Copy to clipboard
Posted by: mingjob
Posted on: 2005-01-14 09:26

没有定义MyInput变量

3.Re:高手们 谁可以告诉我这个程序哪里错那啊~? [Re: adamliu84] Copy to clipboard
Posted by: yuyu_2434
Posted on: 2005-01-14 14:10

同意上面

4.Re:高手们 谁可以告诉我这个程序哪里错那啊~? [Re: adamliu84] Copy to clipboard
Posted by: adamliu84
Posted on: 2005-01-14 22:57

在我运行的这个文件夹中,有个.class的MyInput 文件啊~~ 所以应该不是这个原因啊

5.Re:高手们 谁可以告诉我这个程序哪里错那啊~? [Re: adamliu84] Copy to clipboard
Posted by: wan0000
Posted on: 2005-01-17 19:35

for (j=0; j<a[0].length; j++)

好象应该是for (j=0; j<a[m].length; j++)

for (m=0;m<n;m++)
{
for (j=0; j<a[0].length; j++)
a [m][j]=MyInput.readDouble();
System.out.println("please ENTER the other three length of the triangle's lines:");
}
这个循环好象有问题啊!!

6.Re:高手们 谁可以告诉我这个程序哪里错那啊~? [Re: adamliu84] Copy to clipboard
Posted by: cxy19822003
Posted on: 2005-01-17 20:22

if (total<=0)
System.out.println("The ENTER numbers are wrong!!!");
这里少了ELSE
System.out.println("The campus's area is "+total+"square meters");

7.Re:高手们 谁可以告诉我这个程序哪里错那啊~? [Re: wan0000] Copy to clipboard
Posted by: woaizpgf
Posted on: 2005-01-18 10:16

wan0000 wrote:
for (j=0; j<a[0].length; j++)

好象应该是for (j=0; j<a[m].length; j++)

for (m=0;m<n;m++)
{
for (j=0; j<a[0].length; j++)
a [m][j]=MyInput.readDouble();
System.out.println("please ENTER the other three length of the triangle's lines:");
}
这个循环好象有问题啊!!

好象不对,a[n].length 中不管n等与几,他的值都是 4,所以应该没影响.

8.Re:高手们 谁可以告诉我这个程序哪里错那啊~? [Re: cxy19822003] Copy to clipboard
Posted by: woaizpgf
Posted on: 2005-01-18 10:27

cxy19822003 wrote:
if (total<=0)
System.out.println("The ENTER numbers are wrong!!!");
这里少了ELSE
System.out.println("The campus's area is "+total+"square meters");

if (total<=0)
System.out.println("The ENTER numbers are wrong!!!");
等价于
if (total<=0)
{System.out.println("The ENTER numbers are wrong!!!");}
else{}
所以也对,楼主的编程习惯不好.
我是刚学,都是个人猜测的,如有错误,请及时指正,免得误人误己,谢谢Big Smile

9.Re:高手们 谁可以告诉我这个程序哪里错那啊~? [Re: adamliu84] Copy to clipboard
Posted by: woaizpgf
Posted on: 2005-01-18 10:31

num (double[][] a, int n)
在double和[][] 之间加个空格试试

10.Re:高手们 谁可以告诉我这个程序哪里错那啊~? [Re: adamliu84] Copy to clipboard
Posted by: cxy19822003
Posted on: 2005-01-18 13:24

楼上的你分析的不对。
程序1
class Hello{
  
  public static void main(String[] args){
    
    int i=3;
    if(i==3)
    System.out.println("aaa");
    else
    System.out.println("bbb");
    
  }
  
}

程序二:
class Hello{
  
  public static void main(String[] args){
    
    int i=3;
    if(i==3)
    System.out.println("aaa");
  
    System.out.println("bbb");
    
  }
  
}
两个程序结果分别是:

11.Re:高手们 谁可以告诉我这个程序哪里错那啊~? [Re: adamliu84] Copy to clipboard
Posted by: cxy19822003
Posted on: 2005-01-18 13:24



12.Re:高手们 谁可以告诉我这个程序哪里错那啊~? [Re: adamliu84] Copy to clipboard
Posted by: chenyf
Posted on: 2005-01-18 16:26

楼主说:在我运行的这个文件夹中,有个.class的MyInput 文件啊~~ 所以应该不是这个原因啊 !
既然你有一个包含MyInput 的.class文件,你就应该在该程序的开头inport该class文件,然后创建该class的MyInput 对象,然后对该对象进行操作才对,你们认为呢?


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923