![](/img/trans.png)
[英]the contents of arraylist are printed using println. I want a similar functionality for my created objects without using toString() function in java
[英]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.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.