Hi all,

I want to display the Number values instead of String.

For example, if the User gives the Input as fifty, i displayed the Output as 50.

Is any existing method in Java to call for displaying Numbers?

Or how can i solve this problem?

Thanks in advance and Waiting for your valuable reply..

Myl

There is no such method, you need to create your own:

String strNum = "fifty";
int num = 0;
if (num.equalsIgnoreCase(fifty)) {
  num = 50;
}

OK thanks for your reply, but i want to displayed the output as Number, whatever the user gives an Input..

If it id default number means i Check and Displayed the Default Output, like Fifty.

But various input means?

Please Help me to solve?

Myl

Then write various if statements.
If the user enters twenty one, then separate that input and you have "twenty" and "one". So you don't have to write if statements for every number.
Have a method that returns the number.
For input "twenty" you get 20
For input "one" you get 1
Then add them.
You need if only for the numbers:
1,2,3,....20.
30,40,50,...100
The rest are a combination of the above words:
one hundred and twenty seven

i didn't quite get your last post
u mean when somebody types "fifty", then output is 50 ?

import java.io.*;

/**
    This class demonstrates how to read a line of text from the keyboard
*/
class ReadLine{
    public static void main(String[] args) throws IOException{
        String CurLine = ""; // Line read from standard in
        
        System.out.println("Enter fifty, the output will be 50 ");
        InputStreamReader converter = new InputStreamReader(System.in);
        BufferedReader in = new BufferedReader(converter);
        int num;

        
        while (!(CurLine.equals("fifty"))){
            CurLine = in.readLine();
            
            if (!(CurLine.equals("fifty"))){
                System.out.println("You typed: " + CurLine);
            }
            else if (CurLine.equalsIgnoreCase("fifty")) {
            num = parseInt(CurLine);
            }
        System.out.println(num);
        }
    }
}
if (CurLine.equalsIgnoreCase("fifty")) {
            num = parseInt(CurLine);
            }

What class is the parseInt method in?
I've not seen a method that converts the name of a number("fifty") to an int.

int num = 0;
if (num.equalsIgnoreCase(fifty)) {

int's don't have methods. This shouldn't compile

There isn't a parseInt method, unless you define one. The Integer class has a parseInt method but in order to call it you need: Integer.parseInt("50") not Integer.parseInt("fifty")

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.