被告知放置;在我的方法

时间:2014-09-25 21:45:27

标签: java

import java.util.Scanner;

public class CoinCounter {

  public static void main(String[] args) { 

    Scanner keyboard = new Scanner(System.in);

    System.out.print("Enter the number of toonies: ");
    int t = keyboard.nextInt();

    System.out.print("Enter the number of loonies: "); 
    int l = keyboard.nextInt(); 

    System.out.print("Enter the number of quarters: "); 
    int q = keyboard.nextInt(); 

    System.out.print("Enter the number of dimes: "); 
    int d = keyboard.nextInt(); 

    System.out.print("Enter the number of nickels: "); 
    int n = keyboard.nextInt();   

    int coinCounter = total(t,l,q,d,n);
    System.out.println("The total value of the coins is " + coinCounter + " cents"); 
    finalMessage; 

    static int total(int t , int l , int q , int d , int n) {
      return t*200 + l*100 + q*25 + d*10 + n*5;  
    }//total of coins 

    static String finalMessage( ); {
       System.out.print("Cole Coin Counter Company, 2014"); 
    }//final message

  }//main


}//coinCounter

2 个答案:

答案 0 :(得分:4)

问题看起来像是在这里:

finalMessage; 

那应该是

finalMessage();

此外,您已经在方法中嵌套了一个方法 - 坏消息。 finalMessage()不应在main()内。

答案 1 :(得分:2)

static String finalMessage( ); {

由于;之后的(),这会产生语法错误。简单地说就是这样:

static String finalMessage() {

史蒂夫指出,当你调用一个方法时,你必须使用括号,如下所示:

finalMessage();

此外,正如史蒂夫所指出的那样,方法的定义必须超出所有其他方法。