Skip to content

Instantly share code, notes, and snippets.

@charsyam
Created June 18, 2018 02:32
Show Gist options
  • Save charsyam/c82970c8f079b66ff5f18cb84d83bc5a to your computer and use it in GitHub Desktop.
Save charsyam/c82970c8f079b66ff5f18cb84d83bc5a to your computer and use it in GitHub Desktop.
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