英文:
Java code gives no output, returns "java -classpath .:target/dependency/* Main"
问题
I'm trying to create Java code that will find the area of the following sketch:
I'm trying to find the area of this shape
However, my code (after debugging) returns the following in the console:
java -classpath .:target/dependency/* Main
Here is the code that I tried to run:
class Main {
public static void main(String[] args) {
areaObject(10, 12, 8, 6);
}
static double areaObject(double rectangleLength, double rectangleWidth, double triangleHeight, double missingTriangleHeight){
double rectangleArea = rectangleLength * rectangleWidth;
double triangleArea = 0.5 * triangleHeight * rectangleWidth;
double missingTriangleArea = 0.5 * rectangleWidth * missingTriangleHeight;
return rectangleArea + triangleArea - missingTriangleArea;
}
}
I just started learning Java and decided to try and go back to the basics, and tried to add two numbers with functions. However, the code returned the same response:
java -classpath .:target/dependency/* Main
Here is the code for adding two numbers:
class Main{
public static double addition(double firstNum, double secondNum){
return firstNum + secondNum;
}
public static void main(String[] args) {
addition(2, 3);
}
}
I'm sorry if I'm slandering Java syntax or breaking lots of Java rules; I am new to Java and just started learning. Thank you!
英文:
I'm trying to create Java code that will find the area of the following sketch:
I'm trying to find the area of this shape
However, my code (after debugging) returns the following in the console:
java -classpath .:target/dependency/* Main
Here is the code that I tried to run:
class Main {
public static void main(String[] args) {
areaObject(10, 12, 8, 6);
}
static double areaObject(double rectangleLength, double rectangleWidth, double triangleHeight, double missingTriangleHeight){
double rectangleArea = rectangleLength * rectangleWidth;
double triangleArea = 0.5* triangleHeight * rectangleWidth;
double missingTriangleArea = 0.5 * rectangleWidth * missingTriangleHeight;
return rectangleArea + triangleArea - missingTriangleArea;
}
}
I just started learning Java and decided to try and go back to the basics, and tried to add two numbers with functions. However, the code returned the same response;
java -classpath .:target/dependency/* Main
Here is the code for adding two numbers:
class Main{
public static double addition(double firstNum, double secondNum){
return firstNum + secondNum;
}
public static void main(String[] args) {
addition(2, 3);
}
}
I'm sorry if I'm slandering Java syntax or breaking lots of Java rules; I am new to Java and just started learning. Thank you!
答案1
得分: 1
控制台显示用于执行您的程序的命令;您的程序目前不会输出任何内容。
areaObject(10, 12, 8, 6);
获取面积但不做任何操作。可能您希望显示结果,如:
System.out.println(areaObject(10, 12, 8, 6));
这将输出:
132.0
第二个程序也没有输出。
System.out.println(addition(2, 3));
将输出:
5.0
英文:
The console is displaying the command used to execute your program; your program does not currently output anything.
areaObject(10, 12, 8, 6);
Gets the area but does nothing with it. Presumably you want to display the result like
System.out.println(areaObject(10, 12, 8, 6));
Which outputs
132.0
The second program also outputs nothing.
System.out.println(addition(2, 3));
Would output
5.0
答案2
得分: 0
你可以使用
System.out.println(areaObject(10, 12, 8, 6));
和
System.out.println(addition(2, 3));
英文:
You can use
System.out.println(areaObject(10, 12, 8, 6));
and
System.out.println(addition(2, 3));
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论