Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 给出答案数组的用户输入_Arrays_Input_Int_Double - Fatal编程技术网

Arrays 给出答案数组的用户输入

Arrays 给出答案数组的用户输入,arrays,input,int,double,Arrays,Input,Int,Double,我试图创建一个简短的代码,允许用户输入,并根据输入显示一个数组 我试图显示下落物体的速度和加速度。输入是间隔的数量和间隔之间的时间 我在int和double方面也有问题。。 我的代码到目前为止,我觉得我没有得到任何进一步的 package fall; import java.util.Scanner; public class fallSpeed { public static void main(String[] args) { Scanner input = new Sc

我试图创建一个简短的代码,允许用户输入,并根据输入显示一个数组

我试图显示下落物体的速度和加速度。输入是间隔的数量和间隔之间的时间

我在int和double方面也有问题。。 我的代码到目前为止,我觉得我没有得到任何进一步的

package fall;
import java.util.Scanner;
public class fallSpeed {

    public static void main(String[] args) {

    Scanner input = new Scanner(System.in);
    System.out.print("Look at momentant(1), or interval (2):");
    int alternativ = input.nextInt();

    if (alternativ == 1) {

    System.out.print("Seconds of free fall:");

    int x;
    x = input.nextInt();

    double a = 9.81;
    double d;
    double v;

    v = x * a;
    d = 0.5 * v * x;
    if (x < 0) {
        System.out.println("Number must be over 0");
    }

    else{


    System.out.println("Distance:" + d + " " + "meter(s)");
    System.out.println("Speed after" + " " + x + " " + "sec.:" + v + " " + "m/s");
    }
    }

    if (alternativ == 2) { 

        System.out.print("Numbers of intervalls:");
        int ant = input.nextInt();
        System.out.print("Time between intervalls:");
        int step = input.nextInt();


            double [] a;
            //a.length;
            double [] v;
            double [] d;

            double[] obs= new double [ant];

            double[] speed;
            double[] acc;
            //double[] counter;

                for (ant=0;ant<=obs.length;ant++) 
                    int [] antall = [obs.length];

                    //int [] antall  = new int [ant];       
            //      array [counter] = (int) ant*step;
            //      
            //      fart = obs * a;
            //      array[acc] = (int) (speed* counter * 0.5);

                    System.out.print(ant);          
                    //for(int i=0;i<n;i++){//for reading array
                      //  arr[i]=s.nextInt();
        }
    }
}   
package-fall;
导入java.util.Scanner;
公共类下降速度{
公共静态void main(字符串[]args){
扫描仪输入=新扫描仪(System.in);
系统输出打印(“查看动量(1)或间隔(2):”;
int alternativ=input.nextInt();
如果(可选IV==1){
系统输出打印(“自由落体秒:”;
int x;
x=input.nextInt();
双a=9.81;
双d;
双v;
v=x*a;
d=0.5*v*x;
if(x<0){
System.out.println(“数字必须大于0”);
}
否则{
System.out.println(“距离:“+d+”+“米”);
System.out.println(“速度在“+”+x+”+“秒之后:“+v+”+“m/s”);
}
}
如果(alternativ==2){
系统输出打印(“间隔数:”);
int ant=input.nextInt();
系统输出打印(“间隔时间:”);
int step=input.nextInt();
双[]a;
//a、 长度;
双[]v;
双[]d;
double[]obs=新的double[ant];
双[]速度;
双[]acc;
//双[]计数器;

for(ant=0;antI)已经检查了您的代码。但是无法理解那里发生了什么。您能解释一下您想要什么,解释一下double[]a;//a.length;double[]v;double[]d;double[]obs=new double[ant];double[]speed;double[]acc;//double[]counter;欢迎使用堆栈溢出!您可以学习并创建一个示例。这使我们更容易帮助您。是的,很抱歉,这有点不清楚,但我稍后将尝试使用对象的计算速度创建数组,如ex:speed[0,5,10].我可能定义这些数组有点早,但我正在尝试创建具有观察值的数组,这将再次生成具有速度和加速度的匹配数组