any time a number is present in a word inflate its value by 1........
for eg, input anyone up four tennis
output anytwo up five elevennis

import java.io.*;
public class inflationary
{
public void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String num[]=new String[14];
num[0]="zero";
num[1]="one";
num[2]="two";
num[3]="three";
num[4]="four";
num[5]="five";
num[6]="six";
num[7]="seven";
num[8]="eight";
num[9]="nine";
num[10]="ten";
num[11]="eleven";
num[12]="twelve";
num[13]="thirteen";
String text;
String newtext=" ",word=" ";
System.out.println("ENTER A SENTENCE");
text=br.readLine();
int i,j;
int len=text.length();
for(i=0;i<len;i++)
{
if(text.charAt(i)!=' ')
{
word=word+text.charAt(i);
for(j=0;j<num.length-1;j++)
{
if(word==num[i])
{
newtext=text.replace(num[i],num[i+1]);
}
}
}
}
System.out.println(newtext);
}
}

no output came and no error was shown ..maybe there is some logical mistake pls help

Recommended Answers

All 3 Replies

Are you using an IDE with a debugger? If not, download Eclipse or Netbeans and walk through step by step and find your errors.

Its successfully compiled.....
but.....

Ok, first, your main method signature is wrong. It should be

public static void main(String[] args) throws IOException

Next, you're only grabbing one letter from the input stream at a time. You should use a StringTokenizer or String.split(...) to split your input into an array of words. For example, using String.split:

String[] result = "this is a test".split("\\s");

produces an array of String with each word.
Then loop over your array and use String.contains(...) to determine if your word contains one of the key words.
That should get you on your way. Study the String class - it has a lot of helpful methods for parsing strings.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.