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...
DESCRIPTION Create a program to calculate and print basic stats on a set of a given...
DESCRIPTION Create a program to calculate and print basic stats on a set of a given input values representing students' scores on an exam. 1) Ask the user for the total number of exam scores to be input (assume a positive integer will be given). 2) Create an array to hold all the exam scores and then get all the scores from input to put into the array. For example, if the user input 10 in step (1) then you...
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.
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...
Beginning Python Programming - Sorting: Write and test a Python program to print a set of...
Beginning Python Programming - Sorting: Write and test a Python program to print a set of real numbers in descending order. The program should also print out the median of the numbers input and how many numbers were input. The program should read in numbers until a negative number is read. The negative number serves as a sentinel or marker telling the program when to stop reading numbers. The program should then sort the numbers and print them out in...
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?
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,...
Write and test a Python program to print a set of real numbers in descending order....
Write and test a Python program to print a set of real numbers in descending order. The program should also print out the median of the numbers input and how many numbers were input. The program should read in numbers until a negative number is read. The negative number serves as a sentinel or marker telling the program when to stop reading numbers. The program should then sort the numbers and print them out in order from largest to smallest....
CHALLENGE ACTIVITY 3.12.1: String comparison: Detect word. Write an if-else statement that prints "Goodbye" if userString...
CHALLENGE ACTIVITY 3.12.1: String comparison: Detect word. Write an if-else statement that prints "Goodbye" if userString is "Quit", else prints "Hello". End with newline. import java.util.Scanner; public class DetectWord { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); String userString; userString = scnr.next(); /* Your solution goes here */ } }
Suppose that you are given a set of words; and two words from the set: word...
Suppose that you are given a set of words; and two words from the set: word 1 and word 2. Write a program which will transform word 1 into word 2 by changing a single letter in word 1 at a time. Every transition that word 1 takes will have to be in the set of words. You must output the smallest sequence of transitions possible to convert word 1 into word 2. You may assume that all the words...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT