2017-03-22 87 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)); 

,我得到這個錯誤我的所有打印Fs PrintStream類型中的方法printf(String,Object [])不適用於參數(String,String,int) 請幫助

+0

你在哪一行得到錯誤? –

+3

適合我。 –

+0

提供的代碼正常工作。 –

回答

-1

將每個語句更改爲如下所示。不要通過第二個參數作爲字符串see here

System.out.printf("%-22s %d%n Year" , cal.get(Calendar.YEAR)); 
相關問題