如何在Java中将罗马数字串与双倍相乘?

时间:2015-09-05 02:33:08

标签: java switch-statement case

我是一个java程序的新手,我有一个功课,当我从一个用户输入作为字符串时,我必须使用开关决策结构将其转换为带有.11111的双倍和多倍。

A string input from user has to be a number in roman numeral which is I, II, III, IV, and so on....


//This is my program
package practiceNum;
import java.util.Scanner;

public class practiceNum{
    class stastic void main(String[] args){

    String num_In_Roman;    //declare a string

    Scanner keyboard = new Scanner(System.in);  //read input words

    System.out.println("Enter a roman numerals from I to X: "); //asking user input
    num_In_Roman = keyboard.nextLine();

    switch(num_In_Roman){

    case "I":
    break;

    case "II":
    break;

    //and so on until 10 (X) in roman numerals. 
    default:
        System.out.println("Invalid Number!");
    }

    //end of body program here
    }

}



Here's what i did to calculate my math but still giving me an error.

Double value = Double.parseDouble(num_In_Roman); //convert string into double

case "I":
value *= .111111;
System.out.println(value);
break;


someone help please.

1 个答案:

答案 0 :(得分:1)

这是不好的方法,但这是你可以做的:

case "I":
value = 1 * .111111;
System.out.println(value);
break;

case "II":
value = 2 * .111111;
System.out.println(value);
break;