小编Sam*_*Sam的帖子

我该如何修复这个公式?

我刚开始学习Java.我目前正在为平台游戏编写基本代码,我遇到了一个计算y平台游戏中角色最终位置的公式的问题.

我试图编码的公式是

y = y0 + vy * t - ( 1/2 * g * t^2)
Run Code Online (Sandbox Code Playgroud)

其中,
y =最终y位置;
y0 =初始y位置;
vy =沿y轴的速度;
g =重力;
t =时间;

下面是我为这个公式编写的代码.(请忽略xPosition的代码)

public class Position {

static double xPosition;
static double yPosition;
final static double gravity = 10.0; //gravity on Earth rounded up to the tens place.

public static double xPosition ( double initialPosition , double xVelocity , double time ) {
    return initialPosition + xVelocity …
Run Code Online (Sandbox Code Playgroud)

java

1
推荐指数
1
解决办法
100
查看次数

将数字,变量和过程作为Java中的参数传递

我刚开始研究如何用Java编程语言编写代码.

我遇到了一个问题,告诉我将数字,变量和表达式作为过程调用的参数传递.我遇到的问题是,当我尝试将数字,变量和表达式作为参数传递给过程调用时,我收到错误(我有27个错误).

下面是我的代码,如果有人能指出我的代码有什么问题,我将非常感激.谢谢.

public class test {

// this is the procedure definition
public static int computeCost ( int quantity , int price ) {
    return quantity * price;
}

public static void main ( String args[] ) 
    // passing numbers as arguments to the procedure call "cost"
    System.out.println ( computeCost ( 7 , 12 ) );

    // passing variables as arguments to the procedure call "cost"
    int a = 5;
    int b = 7;
    System.out.println ( computeCost ( a …
Run Code Online (Sandbox Code Playgroud)

java argument-passing

0
推荐指数
1
解决办法
207
查看次数

标签 统计

java ×2

argument-passing ×1