簡體   English   中英

我想在 println 中添加一個 function

[英]I want to add a function in a println

我正在嘗試將用戶輸入的名稱添加到 Java 的打印行中

 System.out.printf("According to your survey, an average of %.2f people rode the per day.",  media );

我想將它添加到文本“rode the...”的部分

首先獲取用戶輸入。 然后添加到打印行

String input = input.next();
 System.out.printf("According to your survey, an average of %.2f people" +input +  " rode the per day.",  media );
float media = 1.5f;
Scanner stdin = new Scanner(System.in);
System.out.printf("According to your survey, an average of %.2f people rode the %s per day.",
                  media,
                  stdin.nextLine());

運行上述代碼時,在輸入值並按ENTER之前,您不會看到任何打印內容。 例如,如果您輸入 Jabberwocky 1 ,則將顯示以下行:

According to your survey, an average of 1.50 people rode the Jabberwocky per day.

1 Jabberwocky

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM