繁体   English   中英

将变量调用回main

[英]Calling variables back to main

我应该在方法中找到五角大楼的区域,然后将其调用回main,以便可以将其打印到.txt文件中。 我将所有事情都完美地工作了,然后当我尝试将其分解并将其放入方法的方法中时,我不断收到此错误: The method pentegon(int) in the type ABhw4part4 is not applicable for the arguments ()

在代码行中, double area = pentegon();

(ABhw4part4是项目名称)

当我尝试将方程式的答案返回主函数时,似乎出现了问题

我在另一个涉及字符串和字符的问题上遇到了类似的问题

我将不胜感激

import java.io.File;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

public class ABhw4part4 {

public static void main(String[] args) throws IOException {

/* Write a method to calculate the area of a pentagon.

Call this method from MAIN and print the result.
Create a file and write all data to the file.

Expected Output:

Input the number of sides: 5
Input the side: 6
The area of the pentagon is 61.93718642120281
Expected file content:
Number of sides: 5
Side: 6*/

File myFile = new File("C://temp//ABhw4part4.txt");


if (myFile.createNewFile() == true) {
System.out.println("file is created");
} else {
System.out.println("file already exists");
}
PrintWriter writer = new PrintWriter(myFile);
Scanner sides = new Scanner (System.in);
int nos, sl;


System.out.println("enter the number of sides");
nos = sides.nextInt();
writer.println(nos);

System.out.println("enter the length of the sides");
sl = sides.nextInt();
writer.println(sl);


double area = pentegon();
System.out.println("area of the pentagon="+ area);
writer.println(area);
writer.close();

}
static double pentegon(int sl) {
double A = (5 * Math.pow(sl, 2)) / (4 * Math.tan(Math.PI /5));
return A;
}
}

您需要将参数传递给方法pentagon。 现在你这样称呼它

double area = pentegon();

应该在哪里这样称呼

double area = pentegon(sl);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM