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 Post>I am just getting started and can not find a Java equivalent to C++'s scanf command.
You shouldn't be using scanf in C++. The best way to parse input remains the same for C++ and Java: read a line and then tokenize it.
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 Post>String Menu_Opt[] = {" "};
What makes you think that Menu_Opt has more than index 0? The size is derived from the initialization list, which contains exactly one item.
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.