• <small id='yLpxa'></small><noframes id='yLpxa'>

    <i id='yLpxa'><tr id='yLpxa'><dt id='yLpxa'><q id='yLpxa'><span id='yLpxa'><b id='yLpxa'><form id='yLpxa'><ins id='yLpxa'></ins><ul id='yLpxa'></ul><sub id='yLpxa'></sub></form><legend id='yLpxa'></legend><bdo id='yLpxa'><pre id='yLpxa'><center id='yLpxa'></center></pre></bdo></b><th id='yLpxa'></th></span></q></dt></tr></i><div id='yLpxa'><tfoot id='yLpxa'></tfoot><dl id='yLpxa'><fieldset id='yLpxa'></fieldset></dl></div>
    • <bdo id='yLpxa'></bdo><ul id='yLpxa'></ul>
  • <tfoot id='yLpxa'></tfoot>

    1. <legend id='yLpxa'><style id='yLpxa'><dir id='yLpxa'><q id='yLpxa'></q></dir></style></legend>

        MissingFormatArgumentException 错误

        时间:2023-09-29
          <tfoot id='z48hF'></tfoot>

              <bdo id='z48hF'></bdo><ul id='z48hF'></ul>
              <legend id='z48hF'><style id='z48hF'><dir id='z48hF'><q id='z48hF'></q></dir></style></legend>
                <tbody id='z48hF'></tbody>
            • <small id='z48hF'></small><noframes id='z48hF'>

                  <i id='z48hF'><tr id='z48hF'><dt id='z48hF'><q id='z48hF'><span id='z48hF'><b id='z48hF'><form id='z48hF'><ins id='z48hF'></ins><ul id='z48hF'></ul><sub id='z48hF'></sub></form><legend id='z48hF'></legend><bdo id='z48hF'><pre id='z48hF'><center id='z48hF'></center></pre></bdo></b><th id='z48hF'></th></span></q></dt></tr></i><div id='z48hF'><tfoot id='z48hF'></tfoot><dl id='z48hF'><fieldset id='z48hF'></fieldset></dl></div>

                1. 本文介绍了MissingFormatArgumentException 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我已经成功编译了我的库存程序:

                  //Inventory.java 第 1 部分//这个程序是计算电子部相机库存的价值导入 java.util.*;导入 javax.swing.*;导入 java.awt.event.*;导入java.io.*;公共类库存{公共静态无效主要(字符串 [] 参数){//创建扫描器以从命令窗口获取输入扫描仪输入 = 新扫描仪(System.in);字符串名称;int 项目编号;//第一个要相乘的数字int itemStock;//第二个要相乘的数字双项价格;//双倍总价值;//number1 和 number2 的乘积while(true){//无限循环//创建新的相机对象System.out.print("请输入部门名称:");//迅速的String itemDept = input.nextLine();//读取用户名if(itemDept.equals("stop"))//退出循环休息;{System.out.print("请输入项目名称:");//迅速的名称 = input.nextLine();//读取用户的第一个数字input.nextLine();}System.out.print("请输入商品编号:");//迅速的itemNumber = input.nextInt();//读取用户的第一个数字input.nextLine();而(项目编号 <= -1){System.out.print("请输入有效数字:");//迅速的itemNumber = input.nextInt();//从用户 input.nextLine() 中读取第一个数字;}/* while 语句,条件是输入负数提示用户输入正数 */System.out.print("输入手头的物品数量:");//迅速的itemStock = input.nextInt();//读取用户的第一个数字input.nextLine();而(项目库存 <= -1){System.out.print("输入正数的手头物品数:");//迅速的itemStock = input.nextInt();//读取用户的第一个数字input.nextLine();}/* while 语句,条件是输入负数提示用户输入正数 */System.out.print("输入商品价格:");//迅速的itemPrice = input.nextDouble();//从用户那里读取第二个数字input.nextLine();而(项目价格 <= -1){System.out.print("请输入商品价格的正数:");//迅速的itemPrice = input.nextDouble();//读取用户的第一个数字input.nextLine();}/* while 语句,条件是输入负数提示用户输入正数 */Cam camera = new Cam(name, itemNumber, itemStock, itemPrice);totalValue = itemStock * itemPrice;//乘数System.out.println("部门名称:" + itemDept);//显示部门名称System.out.println("物品编号:" + camera.getItemNumber());//显示商品编号System.out.println("产品名称:" + camera.getName());//显示项目System.out.println("数量:" + camera.getItemStock());System.out.println("单价" + camera.getItemPrice());System.out.printf("总值为:$%.2f
                  " + totalValue);//显示产品}//结束 while 方法}//结束方法 main}/* 结束类库存 */类凸轮{私有字符串名称;私人 int itemNumber;私有 int itemStock;私人双项价格;私人字符串部门名称;公共凸轮(字符串名称,int itemNumber,int itemStock,double itemPrice){this.name = 名称;this.itemNumber = itemNumber;this.itemStock = itemStock;this.itemPrice = itemPrice;}公共字符串 getName(){返回名称;}公共 int getItemNumber(){返回项目编号;}公共 int getItemStock(){返回项目库存;}公共双 getItemPrice(){返回项目价格;}}

                  <块引用>

                  C:Java>java 库存
                  输入部门名称:电子
                  输入项目名称:相机
                  输入货号:12345
                  输入手头的物品数量:8
                  输入商品价格:100.50
                  部门名称:电子学
                  货号:12345
                  产品名称:相机
                  数量:8
                  单价100.5
                  总值是:
                  线程主"java.util.MissingFormatArgumentException 中的 $Exception:
                  格式说明符.2f"
                  在 java.util.Formatter.format(未知来源)
                  在 java.io.PrintStream.format(未知来源)
                  在 java.io.PrintStream.printf(未知来源)
                  在 Inventory.main(Inventory.java:82)

                  我似乎遇到了这种格式错误,不明白为什么.

                  解决方案

                  如果你使用printf,你需要将占位符指定为<​​code>printf参数以及格式细绳.在您的情况下,您通过附加金额来传递单个字符串,因此会出现错误.

                  System.out.printf("总值为:$%.2f
                  " + totalValue)

                  应该替换为

                  System.out.printf("总值为:$%.2f
                  ", totalValue)

                  I have been successful in compiling my inventory program:

                  // Inventory.java part 1
                  // this program is to calculate the value of the inventory of the Electronics Department's cameras
                  
                  import java.util.*;
                  import javax.swing.*;
                  import java.awt.event.*;
                  import java.io.*;
                  
                  public class Inventory
                  {
                     public static void main(String[] args)
                     {
                         // create Scanner to obtain input from the command window
                         Scanner input = new Scanner (System.in);
                  
                         String name;
                         int itemNumber; // first number to multiply
                         int itemStock; // second number to multiply
                         double itemPrice; //
                         double totalValue; // product of number1 and number2
                  
                  
                  
                     while(true){       // infinite loop
                                // make new Camera object
                  
                        System.out.print("Enter Department name: "); //prompt
                        String itemDept = input.nextLine(); // read name from user
                  
                              if(itemDept.equals("stop"))  // exit the loop
                             break;
                  
                  
                   {
                   System.out.print("Enter item name: "); // prompt
                   name = input.nextLine(); // read first number from user
                   input.nextLine();
                  
                  
                       }
                  
                   System.out.print("Enter the item number: "); // prompt
                   itemNumber = input.nextInt(); // read first number from user
                   input.nextLine();
                    while( itemNumber <= -1){
                   System.out.print("Enter valid number:"); // prompt
                   itemNumber = input.nextInt(); // read first number from user input.nextLine();
                   } /* while statement with the condition that negative numbers are entered
                   user is prompted to enter a positive number */
                  
                   System.out.print("Enter number of items on hand: "); // prompt
                   itemStock = input.nextInt(); // read first number from user
                   input.nextLine();
                    while( itemStock <= -1){
                   System.out.print("Enter positive number of items on hand:"); // prompt
                   itemStock = input.nextInt(); // read first number from user
                   input.nextLine();
                   } /* while statement with the condition that negative numbers are entered
                   user is prompted to enter a positive number */
                  
                   System.out.print("Enter item Price: "); // prompt
                   itemPrice = input.nextDouble(); // read second number from user
                   input.nextLine();
                    while( itemPrice <= -1){
                   System.out.print("Enter positive number for item price:"); // prompt
                   itemPrice = input.nextDouble(); // read first number from user
                   input.nextLine();
                   } /* while statement with the condition that negative numbers are entered
                   user is prompted to enter a positive number */
                  
                  
                   Cam camera = new Cam(name, itemNumber, itemStock, itemPrice);
                  
                   totalValue = itemStock * itemPrice; // multiply numbers
                  
                   System.out.println("Department name:" + itemDept); // display Department name
                   System.out.println("Item number: " + camera.getItemNumber()); //display Item number
                   System.out.println("Product name:" + camera.getName()); // display the item
                   System.out.println("Quantity: " + camera.getItemStock());
                   System.out.println("Price per unit" + camera.getItemPrice());
                   System.out.printf("Total value is: $%.2f
                  " + totalValue); // display product
                  
                         } // end while method
                  
                     } // end method main
                  
                  }/* end class Inventory */
                  
                  class Cam{
                  
                  private String name;
                  private int itemNumber;
                  private int itemStock;
                  private double itemPrice;
                  private String deptName;
                  
                  public Cam(String name, int itemNumber, int itemStock, double itemPrice) {
                  this.name = name;
                  this.itemNumber = itemNumber;
                  this.itemStock = itemStock;
                  this.itemPrice = itemPrice;
                     }
                  
                     public String getName(){
                        return name;
                        }
                  
                  
                  
                     public int getItemNumber(){
                     return itemNumber;
                  
                  }
                  
                     public int getItemStock(){
                     return itemStock;
                  
                  }
                  
                     public double getItemPrice(){
                      return itemPrice;
                  
                  }
                  
                  }
                  

                  C:Java>java Inventory
                  Enter Department name: Electronics
                  Enter item name: camera
                  Enter the item number: 12345
                  Enter number of items on hand: 8
                  Enter item Price: 100.50
                  Department name:Electronics
                  Item number: 12345
                  Product name:camera
                  Quantity: 8
                  Price per unit100.5
                  Total value is:
                  $Exception in thread "main" java.util.MissingFormatArgumentException:
                  Format specifier '.2f'
                  at java.util.Formatter.format(Unknown Source)
                  at java.io.PrintStream.format(Unknown Source)
                  at java.io.PrintStream.printf(Unknown Source)
                  at Inventory.main(Inventory.java:82)

                  I seem to come to this format error and cannot see why.

                  解决方案

                  If you are using printf, you need to specify the placeholders as printf parameters along with the format string. In your case you are passing a single string by appending the amount hence the error.

                  System.out.printf("Total value is: $%.2f
                  " + totalValue)
                  

                  should be replaced by

                  System.out.printf("Total value is: $%.2f
                  ", totalValue)
                  

                  这篇关于MissingFormatArgumentException 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:为什么选择“010"?等于 8? 下一篇:将格式化的字符串写入文件 - Java

                  相关文章

                  最新文章

                  <legend id='89Le7'><style id='89Le7'><dir id='89Le7'><q id='89Le7'></q></dir></style></legend>

                    <bdo id='89Le7'></bdo><ul id='89Le7'></ul>
                  <i id='89Le7'><tr id='89Le7'><dt id='89Le7'><q id='89Le7'><span id='89Le7'><b id='89Le7'><form id='89Le7'><ins id='89Le7'></ins><ul id='89Le7'></ul><sub id='89Le7'></sub></form><legend id='89Le7'></legend><bdo id='89Le7'><pre id='89Le7'><center id='89Le7'></center></pre></bdo></b><th id='89Le7'></th></span></q></dt></tr></i><div id='89Le7'><tfoot id='89Le7'></tfoot><dl id='89Le7'><fieldset id='89Le7'></fieldset></dl></div>
                2. <tfoot id='89Le7'></tfoot>

                    1. <small id='89Le7'></small><noframes id='89Le7'>