Java代码没有输出,返回”java -classpath .:target/dependency/* Main”。

huangapple go评论67阅读模式
英文:

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));

huangapple
  • 本文由 发表于 2023年6月16日 07:25:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76486075.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定