Java 打印结果表时出现问题

Java 打印结果表时出现问题,java,output,Java,Output,我试图让它每次打印一个结果列表的时间是一个整数(ei,2.0,4.0,12.0等),但它只打印第一行结果。if条件是否错误?还是我打印值的命令 包装a03 导入java.util.Scanner /** * *@author Calvin(A00391077)该程序模拟按预设值发射的加农炮 *由用户设置。 */ 公共级大炮{ public static final double DELTA_T = 0.001; public static final double GRAVITY = 9.81;

我试图让它每次打印一个结果列表的时间是一个整数(ei,2.0,4.0,12.0等),但它只打印第一行结果。if条件是否错误?还是我打印值的命令

包装a03

导入java.util.Scanner

/** * *@author Calvin(A00391077)该程序模拟按预设值发射的加农炮 *由用户设置。 */ 公共级大炮{

public static final double DELTA_T = 0.001;
public static final double GRAVITY = 9.81;

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {

    //variables
    Scanner kbd = new Scanner(System.in);
    double muzzleVelocity, muzzleHeight, time, height, velocity;

    //introducing program
    System.out.println("Cannon Simulation");
    System.out.println("-----------------");
    System.out.println();
    System.out.println("This program simulates firing a cannon straight"
            + "up into the air. Velocity");
    System.out.println("is measured in metres per second squared and"
            + " height in meteres.");
    System.out.println();
    System.out.println("By Calvin Elliott (A00391077");
    System.out.println();
    System.out.println("...press enter...");
    kbd.nextLine();
    System.out.println();

    //getting muzzle velocity
    System.out.println("What is the muzzle velocity of the projectile?");
    muzzleVelocity = kbd.nextDouble();

    while (muzzleVelocity <= 0) {
        System.out.println("The velocity must be positive");
        System.out.println("What is the muzzle velocity of the projectile?");
        muzzleVelocity = kbd.nextDouble();
    }

    //getting muzzle height
    System.out.println("what height is the muzzle above the ground?");
    muzzleHeight = kbd.nextDouble();

    while (muzzleHeight <= 0) {
        System.out.println("The position must be positive");
        System.out.println("What height is the muzzle above the ground?");
        muzzleHeight = kbd.nextDouble();

    }

    //calculations
    height = muzzleHeight;
    velocity = muzzleVelocity;
    time = 0;

    System.out.println("TIME    HEIGHT    VELOCITY");
    System.out.println("----    ------    --------");

    while (height > 0) {
        if ((time % 1.0) < DELTA_T) {
            System.out.printf("%6.2f%10.3f%10.3f\n", time, height, velocity);

        }
        height = (height + (velocity * time));
        velocity = (velocity - (GRAVITY * time));
        time = (time + 0.001);

    }

}
公共静态最终双增量T=0.001;
公共静态最终双重力=9.81;
/**
*@param指定命令行参数
*/
公共静态void main(字符串[]args){
//变数
扫描仪kbd=新扫描仪(System.in);
双喷嘴速度,喷嘴高度,时间,高度,速度;
//介绍程序
System.out.println(“火炮模拟”);
System.out.println(“--------------------------”;
System.out.println();
System.out.println(“此程序模拟直接发射大炮”
+“上升到空中。速度”);
System.out.println(“单位为米/秒平方和”
+“高度单位为米。”);
System.out.println();
System.out.println(“由卡尔文·埃利奥特(A00391077))编写;
System.out.println();
System.out.println(“…按enter…”);
kbd.nextLine();
System.out.println();
//获得初速
System.out.println(“弹丸的初速是多少?”);
喷嘴速度=kbd.nextDouble();

而(muzzleVelocity则是通过
速度*时间
增加高度,这是每次迭代的绝对时间量。您需要通过时间增量
增量

例如:

while (height > 0) {
    if ((time % 1.0) < DELTA_T) {
        System.out.printf("%6.2f%10.3f%10.3f\n", time, height, velocity);

    }
    height = (height + (velocity * DELTA_T));
    velocity = (velocity - (GRAVITY * DELTA_T));
    time = (time + DELTA_T);

}
while(高度>0){
如果((时间%1.0)

同样值得注意的是,重力通常应该是负值,这样你就可以把它加到速度上,就像你把速度加到位置上一样。

你试过时间%1.0==0吗?现在一切都很有意义。非常感谢你。@CalElliott,你是新来的。一个好的做法是接受最佳答案。左边的复选标记。。。