阅读下列Java程序和程序说明,将应填入(n)处的字句写在对应栏内。 【说明】清点盒子。本程序当用户输入一个整数值时,一切正常;当输入其他数值时,程序就出错。现在已做了改进,请填空。 import java. text. NumberFormat;

admin2009-02-15  37

问题 阅读下列Java程序和程序说明,将应填入(n)处的字句写在对应栏内。
   【说明】清点盒子。本程序当用户输入一个整数值时,一切正常;当输入其他数值时,程序就出错。现在已做了改进,请填空。
import java. text. NumberFormat;
Public class InventoryLoop
{
   public static void main(String args[])
   {
       String numBoxesIn;
       Int numBoxes;
       Double boxPrice=3.25;
       Boolean gotGoodInput=false;
       NumberFormat currency=NumberFormat.(1);
       do
       {
           System.out. print(“How many boxes do we have?”);
           numBoxesIn=DummiesIO.  (2);
           try
           {
               numBoxes=Integer.parseInt((3));
               system. out. print("The value is");
               system.out. println(currency, format (numBoxes*boxPrice));
               gotGoodInput=true;
               catch((4))
               {
                   System.out.println();
                   System.out. println(That’s not a number.");
               }
       }while((5));//输入不正确时
       System. out.println("That’s that.");
   }
}

选项

答案(1)getCurrencyInstance()或getCurrencyInstance(currentLocale) (2)getString() (3)numBoxesIn (4)NegativeNumberException e (5)!gotGoodInput

解析 (1)getCurrencyInstance()或getCurrencyInstance(currentLocale)
   货币currency对象指向格式化数据NumberFormat类的货币数字格式getCurrencyInstance()。
(2)getString()
   读入货币数字的字符串到NumBoxesIn中。
(3)numBoxesIn
   分析字符串NumBoxesIn的合法性,并转换成整数。
(4)NegativeNumberException e
   捕捉数据格式错误的信息NegativeNumberException e。
(5)!gotGoodInput
   输入不正确时,继续循环输入。
转载请注明原文地址:https://jikaoti.com/ti/J2i7FFFM
0

相关试题推荐
随机试题
最新回复(0)