hi, :cool:
if someone inputs a number in a word (i.e. "two"), how can i take that input and convert it to an int?
-etidd
Printable View
hi, :cool:
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:
Code :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); } } }