Acm java编程问题 [英] Acm java programming problems

查看:98
本文介绍了Acm java编程问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我已经开始编程了2天,我有一个任务要做;赋值是编写一个Java程序,它从用户那里获取一个对象的应用力[N]和质量[kg]并计算它的加速度所以这里是我在消息中写的的代码下面

''''我的问题是程序不会运行,直到赋予FORCE和MASS某些值以及我想从程序中获取用户给出的任何值。我应该怎么做?



我尝试了什么:



包物理;





import acm.program.ConsoleProgram;



公共类物理扩展ConsoleProgram {

public void run(){



readDouble(请强制使用Force);

double Force =



readDouble(请参加弥撒);



double Mass =



双加速度=(力/质量);

println(加速度为:+力/质量);











}







}

Hello all I've started Programming since 2 days and I have an assignment to do ; the assignment is """ Write a Java program that takes applied force[N] and mass[kg] of an object from user and calculate its acceleration """"" so here is the code that I wrote """ in the message below
'''' my problem is that the program won't run till giving the FORCE and MASS certain values and what I want from the program to take any value the user gives. what should I do ?

What I have tried:

package physics;


import acm.program.ConsoleProgram;

public class Physics extends ConsoleProgram {
public void run() {

readDouble("Please entre the Force applied ");
double Force =

readDouble("Please entre the Mass");

double Mass=

double acceleration = ( Force/Mass ) ;
println("The accelration is : "+Force/Mass);





}



}

推荐答案

您的 readDouble 语句未保存用户输入的值。事实上,下面的语句甚至不是有效的Java。因此,您需要捕获read语句的返回值:

Your readDouble statements are not saving the values that the user enters. In fact the statements following are not even valid Java. You need to capture the returned value of the read statements thus:
double Force = readDouble("Please entre the Force applied ");





请参阅 readDouble [ ^ ]。


这篇关于Acm java编程问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆