I am new to Java programming and am converting a program I wrote in C++ to Java. It is a currency conversion program that uses a number of functions to display different menus. It also allows for user input of the menu options to either do a currency conversion or transfer to a different menu which is in a different function.
My question is, I am just getting started and can not find a Java equivalent to C++'s scanf command. I want to use it to read in a string array (for the menu option). My menu option consists of a single letter and a two digit number. By having the menu option defined as an array, I can convert the first letter portion to upper case if the user accidentally enters it in lower case. Then, the number portion can be validated as being a range of valid numbers.
Once I have selected the appropriate menu option to do a conversion, I ask the user to enter a currency amount, defined as a double to be converted to the new currency. Is the same operation code that is used for the menu option able to support this currency amount, or is a different operation code necessary for this?
Recommended Answers
Jump to PostWhat's the scanf function? I'm not familar with C++..
Jump to Postinstead of this:
public static void main(String[] args)
do this:public static void main(String[] args) throws IOException
then it will compile
Jump to PostIt does start at element or index 0. You only have one element in your array or [0]. You have a for loop trying to shove mulltiple things in an array with only one element. I'm not sure I understand what your wanting to do with the menu_Opt array.
Jump to Postremember using the substring function that it also starts at index 0. So if you wanting to get the first character, I think you would do this:
menu_opt.substring(0,1);
and the second one :
menu_opt.substring(1,2);
As for the numeric data, I think it depends on your jdk …
All 14 Replies
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.