[英]The method (double[]) in the type main is not applicable for the arguments (int[])
[英]Main function not working due to one method having parameters ? The method Height(int, int ) is not applicable for arguments ()
// Patrik Maco
// 18/10/21
// VERSION 1
// Write a program that allows the user to input the length, width and height of a room (cm) - volme of balloon (m^3) prints the volume of the room in m^3 and the amount of balloons needed to fill the room.
import java.util.Scanner;
class volume
{
public static void main (String [] a)
{
Run();
System.exit(0);
}
public static int Length()
{ Scanner scanner = new Scanner(System.in);
System.out.println("Enter Values as whole numbers- not as decimals. Do not include measurement. Good example : 5,7,9 Bad example: 3.2, 5cm");
System.out.println("Length of room (in cm) ? ");
int length = scanner.nextInt();
return length;
}
public static int Width()
{ Scanner scanner = new Scanner(System.in);
System.out.println("Enter Values as whole numbers- not as decimals. Do not include measurement. Good example : 5,7,9 Bad example: 3.2, 5cm");
System.out.println("Width of room (in cm) ? ");
int width = scanner.nextInt();
return width;
}
public static int Height(length, width)
{ Scanner scanner = new Scanner(System.in);
System.out.println("Enter Values as whole numbers- not as decimals. Do not include measurement. Good example : 5,7,9 Bad example: 3.2, 5cm");
System.out.println("Height of room (in cm) ? ");
int height = scanner.nextInt();
return height;
System.out.println("Enter the volume of the baloon in M cubed");
float volume_b;
volume_b = scanner.nextFloat();
float RoomVolume;
RoomVolume = ( height * length * width);
System.out.println("The volume of the room is : " + RoomVolume);
float balloon3;
balloon3 = RoomVolume/1000000;
float BalloonAmmount;
BalloonAmmount = balloon3/volume_b;
int n;
n = (int)BalloonAmmount;
System.out.println("The ammount of balloons needed is : " + n);
}
public static void Run()
{ int length = Length();
int width = Width();
int height = Height();
}
}
**方法 Run() 返回錯誤消息 方法 Height(int, int ) 不適用於參數 ()。 我對編碼很陌生,如果可能的話,我喜歡解釋我如何解決這個問題。
高度在它自己的方法中包含兩個參數,但是如果我在 Run() 中輸入相同的參數,我的程序就不會運行**
您的方法Height
存在多個問題。
public static int Height(int length, int width)
return height;
// any code after this point is unreachable
public static void Run()
{
int length = Length();
int width = Width();
int height = Height(length, width); // you need to pass length and width!
}
其他觀察:
main
的末尾顯式調用System.exit(0)
,程序在該點自動結束。SomeClassName
開頭,而方法名通常以小寫字母doSomething()
開頭。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.