计算mas的程序问题 [英] Problem with a program that is suppose to compute mas
问题描述
我是Java新手,目前正在上课,其中一项任务是计算铝块的质量。我们目前在第2周,只进入第二章。我完全迷失了!我已经按照我能找到的书中的每个例子进行了跟踪,并且我在整个地方都遇到了错误。如果有人可以提供帮助,我会非常感激!谢谢!
这是我到目前为止所拥有的!
公共类W3Ex33 {
// main():应用程序入口点
public static void main(String [] args){
int density = 2.7;
int volume = length * Width * height;
int mass = density * volume;
int length
int width
int height
Scanner stdin = new Scanner(System.in); //设置输入字符串
System.out.print(" Length is:"); // read int length
double length = stdin.nextInt();
System.out.print(" Width is:"); //读取int width
double width = stdin.nextInt();
System.out.print(" Height is:"); //读取int height
doublt height = stdin.nextInt();
double volume = length * Width * height; //转换为公制等价物
双重质量=密度*体积; //执行质量计算
System.out.println(带有:的铝块); //显示结果
System.out.println(" length" + length);
System.out.println(" width" + width);
System.out.println(" height" + height);
System.out.println("质量为+质量); < br $>
} //结束方法主要
} //结束课程W3Ex33
>
再次,如果有人可以提供帮助!非常感谢!
I am new to Java and am currently taking a class where one of our assignments is to compute the mass of an aluminum block. We are currently on week 2 and only into our second chapter. I am completely lost! I have followed every example from the book I can find and I am getting errors all over the place. If anyone could help I would be extremely greatful! Thanks!
Here is what I have so far!
public class W3Ex33 {
//main(): application entry point
public static void main(String[] args) {
int density = 2.7;
int volume = length * Width * height;
int mass = density * volume;
int length
int width
int height
Scanner stdin = new Scanner(System.in); //set up input string
System.out.print("Length is: "); //read int length
double length = stdin.nextInt();
System.out.print("Width is: "); //read int width
double width = stdin.nextInt();
System.out.print("Height is: "); //read int height
doublt height = stdin.nextInt();
double volume = length * Width * height; //convert to metric equivalents
double mass = density * volume; //perform mass calculation
System.out.println("An aluminum block with:"); //display results
System.out.println(" length " + length);
System.out.println(" width " + width);
System.out.println(" height " + height);
System.out.println("has a Mass of " + mass);
} //End method main
} // end class W3Ex33
Once again, if anyone can help! Thanks so much!
推荐答案
在下面的代码中
In the code below
< br>
@OP:您是否阅读过编译器试图告诉您的内容?如果您知道如何阅读它们,编译器诊断
非常有用。从快速扫描:
1)宽度和宽度是两个单独的单词/标识符;
2)定义几个变量后没有分号;
3)在设置错误之前使用几个变量;
4)扫描整数并将它们分配给双打。
首先关注编译器试图给你的建议。
亲切的问候,
Jos
@OP: did you read what the compiler was trying to tell you? Compiler diagnostics
are extremey useful if you know how to read them. From a quick scan:
1) width and Width are two separate words/identifiers;
2) no semicolons after the definition of a few variables;
3) use before set errors for a few variables;
4) scanning ints and assigning them to doubles.
First follow up the advice the compiler tried to give to you.
kind regards,
Jos
以下是我个人可以找到的所有更正,结果还剩下:
我还有7个错误:
公共类W3Ex33 {
// main():应用程序入口点
public static void main(String [] args){
double length;
双倍宽度;
双倍高度;
双倍密度= 2.7;
双倍体积=长度*宽度*高度;
双重质量=密度*体积;
扫描仪stdin =新扫描仪(System.in); //设置输入字符串
System.out.print(" Length is:"); // read int length
double length = stdin.nextInt();
System.out.print(" Width is:"); //读取int width
double width = stdin.nextInt();
System.out.print(" Height is:"); //读取int height
double height = stdin.nextInt();
double volume = length * width * height; //转换为公制等价物
双重质量=密度*体积; //执行质量计算
System.out.println(带有:的铝块); //显示结果
System.out.println(" length" + length);
System.out.println(" width" + width);
System.out.println(" height" + height);
System.out.println("质量为+质量); < br $>
} //结束方法主要
} //结束课程W3Ex33
>
我得到的错误如下:
从命令提示符窗口:
C:\ W3Ex33> javac W3Ex33.java
W3Ex33.java:31:找不到符号
符号:类Scanner(我收到此错误消息两行设置输入字符串。
然后为每个输入我得到一个长度宽度高度的体积和质量已经在main中定义(java.lang.String [])
感谢您的帮助!
ALI
Here are all the corrections I could personally find and the results left over:
I still get 7 errors:
public class W3Ex33 {
//main(): application entry point
public static void main(String[] args) {
double length;
double width;
double height;
double density = 2.7;
double volume = length * width * height;
double mass = density * volume;
Scanner stdin = new Scanner(System.in); //set up input string
System.out.print("Length is: "); //read int length
double length = stdin.nextInt();
System.out.print("Width is: "); //read int width
double width = stdin.nextInt();
System.out.print("Height is: "); //read int height
double height = stdin.nextInt();
double volume = length * width * height; //convert to metric equivalents
double mass = density * volume; //perform mass calculation
System.out.println("An aluminum block with:"); //display results
System.out.println(" length " + length);
System.out.println(" width " + width);
System.out.println(" height " + height);
System.out.println("has a Mass of " + mass);
} //End method main
} // end class W3Ex33
The Errors I get are as follows:
From the Command Prompt Window:
C:\W3Ex33>javac W3Ex33.java
W3Ex33.java:31: cannot find symbol
symbol : class Scanner ( I get this error message twice for line to set up input strings.
then for each input I am getting a length width height volume and mass are already defined in main(java.lang.String[])
Thanks For the HELP!
ALI
这篇关于计算mas的程序问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!