hi,
if someone inputs a number in a word (i.e. "two"), how can i take that input and convert it to an int?
-etidd
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
hi,
if someone inputs a number in a word (i.e. "two"), how can i take that input and convert it to an int?
-etidd
see this post:
Words and numbers
edit:
that link is for converting an integer value to a String. Cuju has the right idea, though
I deleted it by accident lol, here it is again:
import java.io.*; import java.util.*; public class ConvertString { public static void main(String args[]) { String input = ""; int number = 0; Scanner key = new Scanner(System.in); System.out.println("Enter a number"); input = key.next(); //CompareTo function if(input.compareToIgnoreCase("two")==0) { number = 2; System.out.println(number); } //equals function else if(input.equals("three")) { number = 3; System.out.println(number); } } }