Question

In: Computer Science

Word to Digit Programming challenge description: Given a string representation of a set of numbers, print...

Word to Digit Programming challenge description:

Given a string representation of a set of numbers, print the digit representation of the numbers.

Input: Your program should read lines from standard input. Each line contains a list of word representations of numbers separated by a semicolon. There are up to 20 numbers in one line. The numbers are "zero" through "nine".

Output: Print the sequence of digits. Test 1 Input zero;two;five;seven;eight;four Expected Test 1 output 025784 Test 2 Input three;seven;eight;nine;two Expected Output 37892

PLEASE USE JAVA:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

public class Main {
/**
* Iterate through each line of input.
*/
public static void main(String[] args) throws IOException {
InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
BufferedReader in = new BufferedReader(reader);
String line;
while ((line = in.readLine()) != null) {

///CODE GOES HERE


System.out.println(line);
}
}
}

Solutions

Expert Solution

Code

import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

public class Main{
/**
* Iterate through each line of input.
*/
public static void main(String[] args) throws IOException {
InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
BufferedReader in = new BufferedReader(reader);
String line;
while ((line = in.readLine()) != null)
 {
   String a[] = line.split(";");
   String res="";
   for(int i=0;i<a.length;i++)
   {
     if(a[i].equals("one"))
         res+="1";
     if(a[i].equals("two"))
         res+="2";
     if(a[i].equals("three"))
         res+="3";
     if(a[i].equals("four"))
         res+="4";
     if(a[i].equals("five"))
         res+="5";
     if(a[i].equals("six"))
         res+="6";
     if(a[i].equals("seven"))
         res+="7";
     if(a[i].equals("eight"))
         res+="8";
     if(a[i].equals("nine"))
         res+="9";
     if(a[i].equals("zero"))
         res+="0";
   }
   System.out.println(res);
 }
}
}

Terminal Work

.


Related Solutions

Split the Number IN JAVASCRIPT Programming challenge description: You are given a number N and a...
Split the Number IN JAVASCRIPT Programming challenge description: You are given a number N and a pattern. The pattern consists of lowercase latin letters and one operation "+" or "-". The challenge is to split the number and evaluate it according to this pattern e.g. 1232 ab+cd -> a:1, b:2, c:3, d:2 -> 12+32 -> 44 Input: Your program should read lines from standard input. Each line contains the number and the pattern separated by a single whitespace. The number...
Problem: Take 3 inputs string, integer, string. If incorrect number of lines are given then print...
Problem: Take 3 inputs string, integer, string. If incorrect number of lines are given then print an error message. Also have to make sure 2nd input is an integer and not a string by default. The function in the program should take the second string and insert it into the first string in the position indicated by the integer input given. The program cannot use strlen() or strncpy() functions and it should check the integer input to make sure it...
From a set of all eight-digit natural numbers, where only the digits from the set {0,1,...
From a set of all eight-digit natural numbers, where only the digits from the set {0,1, 3, 5, 7, 9} are present in decimal notation. we draw one. Calculate the probability of the event that the sum of digits of the drawn number is equal to 3.
a) Given a variable word that has been assigned a string value,write a string expression...
a) Given a variable word that has been assigned a string value, write a string expression that parenthesizes the value of word. So, if word contains "sadly", the value of the expression would be the string "(sadly)"b) Assume that price is an integer variable whose value is the price (in US currency) in cents of an item. Write a statement that prints the value of price in the form "X dollars and Y cents" on a line by itself. So,...
Four numbers are selected without replacement from the set of 1,2,3,4,5,6,7 to form a 4 digit...
Four numbers are selected without replacement from the set of 1,2,3,4,5,6,7 to form a 4 digit number. What is the probability that the number is greater than 5432?
IN PYTHON Given a number of petals, print a string which repeats the phrases "Loves me"...
IN PYTHON Given a number of petals, print a string which repeats the phrases "Loves me" and "Loves me not" for every alternating petal. The last phrase printed (for the last petal picked) should be in all caps. Remember to include a comma and space between phrases, as shown in examples below. Sample Input 1 3 Sample Output 1 "Loves me, Loves me not, LOVES ME" Sample Input 2 1 Sample Output 2 "LOVES ME"
Writing method in Java Given a string, return the sum of the numbers appearing in the...
Writing method in Java Given a string, return the sum of the numbers appearing in the string, ignoring all other characters. A number is a series of 1 or more digit chars in a row. (Note: Character.isDigit(char) tests if a char is one of the chars '0', '1', .. '9'. Integer.parseInt(string) converts a string to an int.) sumNumbers("abc123xyz") → 123 sumNumbers("aa11b33") → 44 sumNumbers("7 11") → 18
a. How many 3-digit numbers can you make using the digits from the set of (3,...
a. How many 3-digit numbers can you make using the digits from the set of (3, 4, 5, 6, 8, 2, 7) without repetitions? b. How many numbers can be made with the digits from the set of (0, 3, 5, 7, 8, 4, 9), which are greater than 0 and less than a thousand (repetitions are allowed)?
Let S be the set of natural numbers which can be written as a non-empty string...
Let S be the set of natural numbers which can be written as a non-empty string of ones followed by a non-empty string of zeroes. For example, 10, 111100 and 11100000 are all in S, but 11 and 1110011 are not in S. Prove that there exists a natural number n∈S, such that 2018 | n.
Write a C++ program to print all the perfect numbers below a certain given number. A...
Write a C++ program to print all the perfect numbers below a certain given number. A perfect number is a number that that is equal too the sum of it's divisors other than itself . For example, 6 and 28 are all perfect numbers. 6 = ( 1+2 +3) 28 = (1+2+4+7+14) Make sure your program conforms to the following requirements: 1. Accept the upper limit from the user (as an integer). 2. Make sure the number is positive (at...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT