2016-09-11 7 views
-8

ここにコードがあります。 ()公共の静的な無効メインが機能しない理由public static void main()は動作していませんか?

import java.io.*; 
class Time 
{ 
int a,b,c,Total; 
Time() 
{ 
    int hr=0; 
    int sec=0; 
    int min=0; 
} 
void time(int hr, int min, int sec) 
{ 
    a=hr; 
    b=min; 
    c=sec; 
} 
void compute() 
{ 
    Total=a*3600+b*60+c*1; 

} 
void display() 
{ 
    System.out.println("Number of hours = " +a); 
    System.out.println("Number of minutes = " +b); 
    System.out.println("Number of seconds = " +c); 
    System.out.println("Total number of seconds = " +Total); 
} 
public static void main()throws IOException 
{ 
    BufferedReader pd=new BufferedReader(new InputStreamReader(System.in)); 
    System.out.println("Enter number of hours : "); 
    int x=Integer.parseInt(pd.readLine()); 
    System.out.println("Enter number of minutes : "); 
    int y=Integer.parseInt(pd.readLine()); 
    System.out.println("Enter number of seconds : "); 
    int z=Integer.parseInt(pd.readLine()); 
    Time obj=new Time(); 
    obj.time(x,y,z); 
    obj.compute(); 
    obj.display(); 
    System.out.println("Thank you for using our service."); 
} 
} 

は、誰かが私に教えていただけますか?私はコーディングを始めているので、これはばかな質問かもしれません。

+1

'メイン(文字列[]引数)として主内部これらの引数を取得することができ:

これは必要とされ、のような1つは、Javaプログラムを実行することによって、コマンドラインからデータを読み取ることができ' –

+0

「うまくいきません」と言うと、コンパイルや実行しようとするとどうなりますか? – halfer

答えて

1

メソッドシグネチャが間違っています。それはパブリックであるべきであるstatic void main(String [] args)throws IOException代わりにstatic void main()throws IOException

0

メソッドシグネチャはwrong.You)が主

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

(に

public static void main()throws IOException 

を変更String型の配列引数を取るべきです。

java <public class name/java file name> arg1 arg2 ... 

一つは

public static void main (String args[]) throws IOException { 
        for (int i=0;i<args.length;i++) { 
        System.out.println(args[i]); 
        } 
. 
. 
. 
. 

        } 
+0

どうすればいいのか教えていただけますか? –

+0

詳細を教えていただけますか? mainのString args []やコマンドラインからのjavaコードの実行について質問していますか? – kratostoical

関連する問題