i am new to a java program and i have a homework where when i get input from a user as an string, i have to convert it to a double and multiple it with a .11111 using a switch decision structure.
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.
This is the bad way, but this is what you can do:
case "I":
value = 1 * .111111;
System.out.println(value);
break;
case "II":
value = 2 * .111111;
System.out.println(value);
break;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.