Skip to content

Instantly share code, notes, and snippets.

@neer2808
Created April 8, 2022 15:08
Show Gist options
  • Save neer2808/c6e1fb7080dbb35f48ea39a291d53e5c to your computer and use it in GitHub Desktop.
Save neer2808/c6e1fb7080dbb35f48ea39a291d53e5c to your computer and use it in GitHub Desktop.
import java.lang.invoke.SwitchPoint;
public class Test {
public static void main(String[] args) {
String str = "two four triple three";
String ans = "";
String strArray[] = str.split(" ");
String ans1="";
System.out.println("String : " + str);
for (int i = 0; i < strArray.length; i++) {
switch (strArray[i])
{
case "one":
ans = ans+"1";
break;
case "two":
ans = ans+"2";
break;
case "three":
ans = ans+"3";
break;
case "four":
ans = ans+"4";
break;
case "five":
ans = ans+"5";
break;
case "six":
ans = ans+"6";
break;
case "seven":
ans = ans+"7";
break;
case "eight":
ans = ans+"8";
break;
case "nine":
ans = ans+"9";
break;
case "zero":
ans = ans+"0";
break;
case "double":
switch(strArray[i+1])
{
case "one":
ans1 = "1";
break;
case "two":
ans1 = "2";
break;
case "three":
ans1 = "3";
break;
case "four":
ans1 = "4";
break;
case "five":
ans1 = "5";
break;
case "six":
ans1 = "6";
break;
case "seven":
ans1 = "7";
break;
case "eight":
ans1 = "8";
break;
case "nine":
ans1 = "9";
break;
case "zero":
ans1 = "0";
break;
}
ans= ans+ans1;
break;
case "triple":
switch(strArray[i+1])
{
case "one":
ans1 = "1";
break;
case "two":
ans1 = "2";
break;
case "three":
ans1 = "3";
break;
case "four":
ans1 = "4";
break;
case "five":
ans1 = "5";
break;
case "six":
ans1 = "6";
break;
case "seven":
ans1 = "7";
break;
case "eight":
ans1 = "8";
break;
case "nine":
ans1 = "9";
break;
case "zero":
ans1 = "0";
break;
}
ans= ans+ ans1+ans1;
}
}
// convert string into integer we will use this
int res = Integer.parseInt(ans);
System.out.println(res);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment