小编use*_*509的帖子

如何在一个字符串中输出一个double到2个decmial位置?

该程序使用itemListener进行温度转换

outputValue是受保护的double

outputString也受到保护

输出是一个JTextField

和输出类型是受保护的char

public void itemStateChanged(ItemEvent e) {
    inputValue =  Double.parseDouble(textField.getText());

    //the input value is converted to the outputValue based on the outputType

    outputString = String.valueOf(outputValue);            //set output value to string
    outputString = String.format(" %0.2f", outputValue);   //format to .00

    output.setText( outputString + (char) 0x00B0 + outputType);}
Run Code Online (Sandbox Code Playgroud)

当我运行程序时,我得到:

Exception in thread "AWT-EventQueue-0" java.util.MissingFormatWidthException: 0.2f,
Run Code Online (Sandbox Code Playgroud)

有很多(未知来源).

java formatting decimal

2
推荐指数
2
解决办法
8863
查看次数

使用Java中的ObjectInputStream从文件中检索String数组?

我的程序基本上是每日计划者.

计划按ObjectOutputStream按月和年保存在文件中.校验

时间表按天安排在一个数组中.校验

计划由ObjectInputStream检索.这是我遇到问题的地方.

public class Calendar {
public String date;
public String[] schedule = new String[31];
Calendar(){


}

public String retrieve(int month, int day, int year) {
    date = Integer.toString(month) + "-"+ Integer.toString(year ) + ".txt";

    try {
        ObjectInputStream input = new ObjectInputStream(new 
FileInputStream(date));
        input.readObject();
        schedule = input;    
//This is where I have the error obviously schedule is a string array and 
//input is an ObjectInputStream so this wont work
        input.close();
        return schedule[day-1];

    } catch (FileNotFoundException e) {
        // …
Run Code Online (Sandbox Code Playgroud)

java arrays string exception objectinputstream

1
推荐指数
1
解决办法
3899
查看次数