![](/img/trans.png)
[英]Error: Main method not found in class Main, please define the main method
[英]Error: Main method not found in class Purchase
創建一個使用 Purchase 類的 Java 程序
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Purchase
{
String ItemName;
double ItemPrice;
int ItemQuantity;
double ItemTotal;
public void setItemName(String newItemName)
{
ItemName = newItemName;
}
public void TotalCost(double newItemPrice, int newItemQuantity)
{
ItemPrice = newItemPrice;
ItemQuantity = newItemQuantity;
}
public void readInput ()
{
Scanner sc = new Scanner (System.in);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try
{
System.out.print("Enter Item Name : ");
ItemName = br.readLine();
}
catch (IOException e)
{
}
System.out.print ("Enter Item Price & Item Quantity.");
System.out.print ("For Example 95.50 Price 8 Quantity is entered as");
System.out.print ("95.50 8");
System.out.println ("Enter price of item & Quantity of Item, now:");
ItemPrice = sc.nextDouble();
ItemQuantity = sc.nextInt();
}
public void writeOutput ()
{
System.out.print(ItemName + " " +ItemPrice + " " +ItemQuantity + " Total Cost " +ItemTotal);
}
public String getItemName()
{
return ItemName;
}
public double getItemPrice()
{
return ItemPrice;
}
public int getItemQuantity()
{
return ItemQuantity;
}
public double TotalCost()
{
double ItemTotal = ItemPrice * ItemQuantity;
return ItemTotal;
}
}
我在哪里以及如何放置靜態 void main (String []args) ??? 幫助請在我運行這個程序時感謝.. 過程完成但我仍然有錯誤:在類中找不到 Main 方法購買請將主要方法定義為:public static void main(String[] args)
您可以將 main 方法放在類中其他方法之間的任何位置。 例如:
public class Purchase
{
String ItemName;
double ItemPrice;
int ItemQuantity;
double ItemTotal;
public static void main(String[] args)
{
Purchase purch = new Purchase();
//further actions here
}
...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.