Converting Words to Numbers [duplicate]











up vote
4
down vote

favorite













This question already has an answer here:




  • How do I compare strings in Java?

    23 answers



  • Converting Words to Numbers in Java

    5 answers




I'm blocked with convert words to numbers on java. I have to convert any words to numbers, but I do not know how to start this work.



I created a small loop for the first 19 numbers. But when they start to come out variable like "" spaces or "-" scripts, "hundred", "thousand" and so on, I get stuck and there's no way to get the problem out.



public static long words(String s) {

for (int i = 0; i <s.length() ; i++) {
String w = "";
w+= s.charAt(i);
w=s;
}
return UniqueWords(s);
}

public static long UniqueWords(String s) {

if (s == "zero") {
return 0;
} else if (s == "one") {
return 1;
} else if (s == "two") {
return 2;
} else if (s == "three") {
return 3;
} else if (s == "four") {
return 4;
} else if (s == "five") {
return 5;
} else if (s == "six") {
return 6;
} else if (s == "seven") {
return 7;
} else if (s == "eight") {
return 8;
} else if (s == "nine") {
return 9;
} else if (s == "ten") {
return 10;
} else if (s == "eleven") {
return 11;
} else if (s == "twelve") {
return 12;
} else if (s == "thirteen") {
return 13;
} else if (s == "fourteen") {
return 14;
} else if (s == "fifteen") {
return 15;
} else if (s == "sixteen") {
return 16;
} else if (s == "seventeen") {
return 17;
} else if (s == "eighteen") {
return 18;
} else if (s == "nineteen") {
return 19;
}
return 0;
}




The objective of the program is that you can convert any word of a number to the quintillon number



Any help will be welcome.



As you can see, I just landed in the programming world and I still have a hard time working with Strings.



Thank you!










share|improve this question















marked as duplicate by tobias_k, azurefrog, Roshana Pitigala, Roddy of the Frozen Peas, Stephen C java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 10 at 7:19


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • On what basis do you want to convert the numbers?
    – Nicholas K
    Nov 9 at 16:50










  • You should use s.equals("num") for comparing strings. In this case it might also be useful to use s.equalsIgnoreCase("num") to ensure that your input is not case sensitive.
    – JPadley
    Nov 9 at 16:51












  • The first 20 numbers are indeed the trickiest, with many "outliers" like "twelve" or "fifteen". Try the next ten, or up to 100. Do you start to see a pattern?
    – tobias_k
    Nov 9 at 16:52












  • see this:stackoverflow.com/questions/26948858/…
    – PhaseRush
    Nov 9 at 18:03















up vote
4
down vote

favorite













This question already has an answer here:




  • How do I compare strings in Java?

    23 answers



  • Converting Words to Numbers in Java

    5 answers




I'm blocked with convert words to numbers on java. I have to convert any words to numbers, but I do not know how to start this work.



I created a small loop for the first 19 numbers. But when they start to come out variable like "" spaces or "-" scripts, "hundred", "thousand" and so on, I get stuck and there's no way to get the problem out.



public static long words(String s) {

for (int i = 0; i <s.length() ; i++) {
String w = "";
w+= s.charAt(i);
w=s;
}
return UniqueWords(s);
}

public static long UniqueWords(String s) {

if (s == "zero") {
return 0;
} else if (s == "one") {
return 1;
} else if (s == "two") {
return 2;
} else if (s == "three") {
return 3;
} else if (s == "four") {
return 4;
} else if (s == "five") {
return 5;
} else if (s == "six") {
return 6;
} else if (s == "seven") {
return 7;
} else if (s == "eight") {
return 8;
} else if (s == "nine") {
return 9;
} else if (s == "ten") {
return 10;
} else if (s == "eleven") {
return 11;
} else if (s == "twelve") {
return 12;
} else if (s == "thirteen") {
return 13;
} else if (s == "fourteen") {
return 14;
} else if (s == "fifteen") {
return 15;
} else if (s == "sixteen") {
return 16;
} else if (s == "seventeen") {
return 17;
} else if (s == "eighteen") {
return 18;
} else if (s == "nineteen") {
return 19;
}
return 0;
}




The objective of the program is that you can convert any word of a number to the quintillon number



Any help will be welcome.



As you can see, I just landed in the programming world and I still have a hard time working with Strings.



Thank you!










share|improve this question















marked as duplicate by tobias_k, azurefrog, Roshana Pitigala, Roddy of the Frozen Peas, Stephen C java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 10 at 7:19


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • On what basis do you want to convert the numbers?
    – Nicholas K
    Nov 9 at 16:50










  • You should use s.equals("num") for comparing strings. In this case it might also be useful to use s.equalsIgnoreCase("num") to ensure that your input is not case sensitive.
    – JPadley
    Nov 9 at 16:51












  • The first 20 numbers are indeed the trickiest, with many "outliers" like "twelve" or "fifteen". Try the next ten, or up to 100. Do you start to see a pattern?
    – tobias_k
    Nov 9 at 16:52












  • see this:stackoverflow.com/questions/26948858/…
    – PhaseRush
    Nov 9 at 18:03













up vote
4
down vote

favorite









up vote
4
down vote

favorite












This question already has an answer here:




  • How do I compare strings in Java?

    23 answers



  • Converting Words to Numbers in Java

    5 answers




I'm blocked with convert words to numbers on java. I have to convert any words to numbers, but I do not know how to start this work.



I created a small loop for the first 19 numbers. But when they start to come out variable like "" spaces or "-" scripts, "hundred", "thousand" and so on, I get stuck and there's no way to get the problem out.



public static long words(String s) {

for (int i = 0; i <s.length() ; i++) {
String w = "";
w+= s.charAt(i);
w=s;
}
return UniqueWords(s);
}

public static long UniqueWords(String s) {

if (s == "zero") {
return 0;
} else if (s == "one") {
return 1;
} else if (s == "two") {
return 2;
} else if (s == "three") {
return 3;
} else if (s == "four") {
return 4;
} else if (s == "five") {
return 5;
} else if (s == "six") {
return 6;
} else if (s == "seven") {
return 7;
} else if (s == "eight") {
return 8;
} else if (s == "nine") {
return 9;
} else if (s == "ten") {
return 10;
} else if (s == "eleven") {
return 11;
} else if (s == "twelve") {
return 12;
} else if (s == "thirteen") {
return 13;
} else if (s == "fourteen") {
return 14;
} else if (s == "fifteen") {
return 15;
} else if (s == "sixteen") {
return 16;
} else if (s == "seventeen") {
return 17;
} else if (s == "eighteen") {
return 18;
} else if (s == "nineteen") {
return 19;
}
return 0;
}




The objective of the program is that you can convert any word of a number to the quintillon number



Any help will be welcome.



As you can see, I just landed in the programming world and I still have a hard time working with Strings.



Thank you!










share|improve this question
















This question already has an answer here:




  • How do I compare strings in Java?

    23 answers



  • Converting Words to Numbers in Java

    5 answers




I'm blocked with convert words to numbers on java. I have to convert any words to numbers, but I do not know how to start this work.



I created a small loop for the first 19 numbers. But when they start to come out variable like "" spaces or "-" scripts, "hundred", "thousand" and so on, I get stuck and there's no way to get the problem out.



public static long words(String s) {

for (int i = 0; i <s.length() ; i++) {
String w = "";
w+= s.charAt(i);
w=s;
}
return UniqueWords(s);
}

public static long UniqueWords(String s) {

if (s == "zero") {
return 0;
} else if (s == "one") {
return 1;
} else if (s == "two") {
return 2;
} else if (s == "three") {
return 3;
} else if (s == "four") {
return 4;
} else if (s == "five") {
return 5;
} else if (s == "six") {
return 6;
} else if (s == "seven") {
return 7;
} else if (s == "eight") {
return 8;
} else if (s == "nine") {
return 9;
} else if (s == "ten") {
return 10;
} else if (s == "eleven") {
return 11;
} else if (s == "twelve") {
return 12;
} else if (s == "thirteen") {
return 13;
} else if (s == "fourteen") {
return 14;
} else if (s == "fifteen") {
return 15;
} else if (s == "sixteen") {
return 16;
} else if (s == "seventeen") {
return 17;
} else if (s == "eighteen") {
return 18;
} else if (s == "nineteen") {
return 19;
}
return 0;
}




The objective of the program is that you can convert any word of a number to the quintillon number



Any help will be welcome.



As you can see, I just landed in the programming world and I still have a hard time working with Strings.



Thank you!





This question already has an answer here:




  • How do I compare strings in Java?

    23 answers



  • Converting Words to Numbers in Java

    5 answers








java






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 16:52









EJoshuaS

6,992102648




6,992102648










asked Nov 9 at 16:47









Sokae

212




212




marked as duplicate by tobias_k, azurefrog, Roshana Pitigala, Roddy of the Frozen Peas, Stephen C java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 10 at 7:19


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by tobias_k, azurefrog, Roshana Pitigala, Roddy of the Frozen Peas, Stephen C java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 10 at 7:19


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • On what basis do you want to convert the numbers?
    – Nicholas K
    Nov 9 at 16:50










  • You should use s.equals("num") for comparing strings. In this case it might also be useful to use s.equalsIgnoreCase("num") to ensure that your input is not case sensitive.
    – JPadley
    Nov 9 at 16:51












  • The first 20 numbers are indeed the trickiest, with many "outliers" like "twelve" or "fifteen". Try the next ten, or up to 100. Do you start to see a pattern?
    – tobias_k
    Nov 9 at 16:52












  • see this:stackoverflow.com/questions/26948858/…
    – PhaseRush
    Nov 9 at 18:03


















  • On what basis do you want to convert the numbers?
    – Nicholas K
    Nov 9 at 16:50










  • You should use s.equals("num") for comparing strings. In this case it might also be useful to use s.equalsIgnoreCase("num") to ensure that your input is not case sensitive.
    – JPadley
    Nov 9 at 16:51












  • The first 20 numbers are indeed the trickiest, with many "outliers" like "twelve" or "fifteen". Try the next ten, or up to 100. Do you start to see a pattern?
    – tobias_k
    Nov 9 at 16:52












  • see this:stackoverflow.com/questions/26948858/…
    – PhaseRush
    Nov 9 at 18:03
















On what basis do you want to convert the numbers?
– Nicholas K
Nov 9 at 16:50




On what basis do you want to convert the numbers?
– Nicholas K
Nov 9 at 16:50












You should use s.equals("num") for comparing strings. In this case it might also be useful to use s.equalsIgnoreCase("num") to ensure that your input is not case sensitive.
– JPadley
Nov 9 at 16:51






You should use s.equals("num") for comparing strings. In this case it might also be useful to use s.equalsIgnoreCase("num") to ensure that your input is not case sensitive.
– JPadley
Nov 9 at 16:51














The first 20 numbers are indeed the trickiest, with many "outliers" like "twelve" or "fifteen". Try the next ten, or up to 100. Do you start to see a pattern?
– tobias_k
Nov 9 at 16:52






The first 20 numbers are indeed the trickiest, with many "outliers" like "twelve" or "fifteen". Try the next ten, or up to 100. Do you start to see a pattern?
– tobias_k
Nov 9 at 16:52














see this:stackoverflow.com/questions/26948858/…
– PhaseRush
Nov 9 at 18:03




see this:stackoverflow.com/questions/26948858/…
– PhaseRush
Nov 9 at 18:03

















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Schultheiß

Liste der Kulturdenkmale in Wilsdruff

Android Play Services Check