【问题标题】:Need help for Java exportJava 导出需要帮助
【发布时间】:2013-11-13 18:40:11
【问题描述】:

我导出了我的 Java 文件,它的工作方式很简单。只是有一个小问题,当扫描仪计算我的输入时,它会输出结果,但应用程序在我收到输出后 1 秒关闭。如何防止我的应用程序关闭?代码是:

最好的问候

奥利弗

import java.util.Scanner;
import java.util.HashMap;

import java.util.*;

public class Valuta {
    public static void main(String[] args){

        double euro, usd, gpb, dkk, done;

        Scanner input = new Scanner(System.in);

        System.out.println("Convert from " +"USD,GPB, DKK or EURO?");
        String temp = (input.nextLine()).toUpperCase();

        System.out.println("to " + "USD,GPB, DKK or Euro?");
        String tempp = (input.nextLine()).toUpperCase();

        Map<String, Double> lookUpMap = new HashMap<String, Double>(){{
            put("EURO", new Double(7.46));
            put("USD", new Double(5.56));
            put("GPB", new Double(8.84));
            put("DKK", new Double (1.0));
            }};


        System.out.println("amount of " + (temp));
        double amount = input.nextDouble();
        done = (lookUpMap.get(temp) / lookUpMap.get(tempp)) * amount;
        System.out.println(done);
    }
    }   

【问题讨论】:

  • 使用循环,在System.out.println(done);之后询问用户是否要退出应用程序,如果要退出应用程序,否则继续循环。

标签: java export


【解决方案1】:

试试这个..

public static void main(String[] args) {

        double euro, usd, gpb, dkk, done;

        Scanner input = new Scanner(System.in);
        String ch = "";
        do{
        System.out.println("Convert from " + "USD,GPB, DKK or EURO?");
        String temp = (input.nextLine()).toUpperCase();
        System.out.println("to " + "USD,GPB, DKK or Euro?");
        String tempp = (input.nextLine()).toUpperCase();
        Map<String, Double> lookUpMap = new HashMap<String, Double>() {
            {
                put("EURO", new Double(7.46));
                put("USD", new Double(5.56));
                put("GPB", new Double(8.84));
                put("DKK", new Double(1.0));
            }
        };

        System.out.println("amount of " + (temp));
        double amount = input.nextDouble();
        done = (lookUpMap.get(temp) / lookUpMap.get(tempp)) * amount;
        System.out.println(done);
        System.out.println("Do you want continue ? Y/N");
        ch = input.nextLine();
        } while(ch.equals("Y"));
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多