-1

我导出了我的 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);
    }
    }   
4

1 回答 1

0

try this..

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"));
    }
于 2013-11-13T18:53:07.217 回答