Created
June 18, 2018 02:32
-
-
Save charsyam/c82970c8f079b66ff5f18cb84d83bc5a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
import java.util.List; | |
import java.util.ArrayList; | |
public class ConvertNumberToDollar { | |
public static String convertNumberToDollar(String input) { | |
String output = ""; | |
for (int i = 0; i < input.length(); i++) { | |
char ch = input.charAt(i); | |
if (ch >= '0' && ch <= '9') { | |
ch = '$'; | |
} | |
output = output + ch; | |
} | |
return output; | |
} | |
public static void main(String [] args) { | |
Scanner sc = new Scanner(System.in); | |
String result = ""; | |
while(true) { | |
//get word from keyboard | |
String input = sc.nextLine(); | |
//if input is "quit" break; | |
if ("quit".equals(input)) { | |
break; | |
} | |
//if word has numbers then change number to '$' | |
String convertedString = convertNumberToDollar(input); | |
//save converted word to string | |
result = result + convertedString; | |
System.out.println(result); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment