2017-03-22 9 views
-3

私はこのコードを入力しています:方法のprintf PrintStream型で(文字列、[]オブジェクト)の引数には適用されません(文字列、文字列、int型)

import java.util.Calendar; //Required to get the instance of date on the computer 
import java.util.Date;  //Required if you want to store instances of the calendar in a varaible 
import java.util.Scanner; //Required to collect input from the user 


public class L01ManagingDate 
{ 

    public static void main(String[] args) 
    { 


    Calendar cal = Calendar.getInstance(); 

    System.out.println(cal);  

    System.out.println("The current date list printed out, but not stored " + cal.getTime()); 

    Date dateNow = cal.getTime(); 
    System.out.println("The current date list stored in a variable " + dateNow); 

    System.out.printf("%-22s %d%n" , "Year" , cal.get(Calendar.YEAR)); 
    System.out.printf("%-22s %d%n" , "Month" , cal.get(Calendar.MONTH)); 
    System.out.printf("%-22s %d%n" , "Month" , cal.get(Calendar.DAY_OF_MONTH)); 
    System.out.printf("%-22s %d%n" , "Week" , cal.get(Calendar.DAY_OF_WEEK)); 
    System.out.printf("%-22s %d%n" , "Day" , cal.get(Calendar.DAY_OF_YEAR)); 
    System.out.printf("%-22s %d%n" , "Week" , cal.get(Calendar.WEEK_OF_YEAR)); 
    System.out.printf("%-22s %d%n" , "Month" , cal.get(Calendar.WEEK_OF_MONTH)); 
    System.out.printf("%-22s %d%n" , "Day of week in month" , cal.get(Calendar.DAY_OF_WEEK_IN_MONTH)); 
    System.out.printf("%-22s %d%n" , "AM (0) or PM (1)" , cal.get(Calendar.AM_PM)); 
    System.out.printf("%-22s %d%n" , "Hour" , cal.get(Calendar.HOUR_OF_DAY)); 
    System.out.printf("%-22s %d%n" , "Minute" , cal.get(Calendar.MINUTE)); 
    System.out.printf("%-22s %d%n" , "Second" , cal.get(Calendar.SECOND)); 
    System.out.printf("%-22s %d%n" , "Millisecond" , cal.get(Calendar.MILLISECOND)); 

と私は上で、このエラーを得ましたPrintF(String、Object [])メソッドは、引数(String、String、int)には適用されません。

+0

どのラインでエラーが表示されますか? –

+3

私にとってうまく動作します。 –

+0

提供されたコードは正常に動作します。 –

答えて

-1

すべての声明を次のように変更してください。文字列として2番目の引数を渡さないでくださいsee here

System.out.printf("%-22s %d%n Year" , cal.get(Calendar.YEAR)); 
関連する問題