Converting strings to numbers

import java.io.*;
import java.util.*;
class D{
     public static void main(String[] args)throws IOException{
     Scanner in = new Scanner (System.in);
     //51 3 15 * - 9 65 13 / - + example of expression to enter
     System.out.print("Enter PostFixExpression :");
     String s = in.next();//I am aware that I cannot read them as characters so I am using string
    while(!s.equals("")){
         if(String.isDigit(s)){//line 13
              System.out.printf("%d",s);
         }else{
              System.out.println("I am not a digit ");
         s = in.next();
     }//main
}//classerror: cannot find symbol method isDigit(java.lang.String) line 13
when I use Character.isDigit(s), it separates the digits, for example 51 becomes a 5 and a 1. How can I manipulate the data so that the digits in the number stays together?
--------------------------------------------------------------------------------

chetah wrote:
error: cannot find symbol method isDigit(java.lang.String) line 13Right. As the error message tells you, String does not have a static isDigit method that takes a String arg.
when I use Character.isDigit(s), it separates the digits, for example 51 becomes a 5 and a 1. No, that's not what isDigit does. It simply tells you whether a given character is a digit or not. You have to separate them yourself first.
How can I manipulate the data so that the digits in the number stays together?Well, if you want to examine the individual characters to test whether they're digits, you'll have to break the String into chars. So look at String's methods to see if you can find one that will help you with that. Note that Strings are immutable, so you already know that your original String will remain untouched.

Similar Messages

  • How to converts string into numbers

    As a beginer now i am asking the above question?
    now i am working with XCode 4.3

    I responded to you here > How to convert pages document into...: Apple Support Communities
    Please do not start duplicate topics 

  • Converting strings to the floating number and plotting

    Hello,
    I have a question regardting converting string of numbers to the floating bumbers and plot for voltage vs. weight.
    The load cell for the ADC resolution is 16 bits, and the voltage will be in between +-5 volts.
    The problem, I have the most is converting the string of numbers to the floating numbers, in my case is the weight.
    Attachments:
    tunnelv1.vi ‏139 KB

    When you say "string of numbers" do you mean an array? What is the specific issue you are having? You seem to have orange wires running all over the place. Give a small example demonstrating the problem.
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • Converting a string of numbers into an array of booleans

    For a homework assignment, I need to convert a string of numbers into an array of booleans.  The string is a bunch of random numbers (0-9) in sequence, with no spaces.  It looks something like this: 0123452348949230740329817438120947392147809231419.  I need to make it so that each even number represents a "True" boolean and so that each odd number represents a "False" boolean.  I think that I first need to convert each element of the string into a number, and then use a case structure (or something) to say, for each element of the array, "If even, then true.  If odd, then false," but I could be wrong.  Any suggestions?

    billko wrote:
    Hooovahh wrote:
    billko wrote:
    Sounds reasonable.  Think about the definition of "odd" and "even" and it will make life a lot easier. 
    I know you are trying to be vague but I'd like to give a key hint.  Use the Quotient and Remainder function.
    LOL maybe that was one of the objectives of the homework. 
    To be fair it sounds like there is more work that is needed.  A new user of LabVIEW will have a hard time figuring out how to process each character one at a time when it isn't in an array.  
    It's just that most people (me at least) stopped thinking about division with quotient and remainder after basic algebra.  I then of course changed my way of thinking when I used LabVIEW.  Still most of the time when you use division you want to know the fractional part as a decimal.  Thinking this way makes the problem more difficult then it needs to be.
    Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
    If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.

  • Is there a way to type cast an array of strings to numbers and back again?

    I'm working on an application where I want to type cast a string like "power supply" into an array of existing numbers. Then sort the existing numbers, and finally convert the casted numbers back into a string so it can be read by the user. In the attachment, you can see my latest attempt with flatten/unflatten data and the 'convert string to byte array'. I can't seem to make this work. Any ideas?
    Thanks - Paul
    Attachments:
    Paul's Temp scan for components.vi ‏56 KB

    OK, here's a quickie (LabVIEW 7.0).
    Simply get the sort key from the 1D array, then build the table.
    Message Edited by altenbach on 10-27-2006 01:34 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    SortedTable.png ‏4 KB
    SortedTable.vi ‏37 KB

  • I would like to read a file and display the results in a table containing both strings and numbers?

    Hi,
    I just need a simple way of doing this as at the moment, i read one line at the time containing strings and numbers, whenever i convert this line to an array i loose the strings, if i want to display it, it displays as a group of lines while i would like to display it as a table with column headers. The file is an .xls worksheet.
    Any suggestions?
    Thanks
    Me

    Hi,
    Look at attach vi.
    If this is not what you need please clarify.
    With ActiveX you can Open Excel, interact with it (read and write values to cells...
    But if you can read it this way, I think it's easier.
    Hope this helps,
    Paulo
    Attachments:
    XL.zip ‏24 KB

  • Convert letters into numbers

    I need to write a method that converts letters from a word into a number according to the telephone buttons.
    I figured I was at a good start by putting the string of the word into a character array, but how would I assign each of those letters to its corresponding number?
    Thanks in advance.

    changes to code that fills the hashmap. more concise (less interpretable)
    import java.util.HashMap;
    import java.util.Map;
    class HashMapTester2
        private Map<Character, Integer> phoneHash;
        // constructor
        // for converting alphabetical characters to numbers based on the
        // phone dialing pad.
        public HashMapTester2()
            phoneHash = new HashMap<Character, Integer>();
            fillMap();
        private void fillMap()
            for (char myChar = 'a'; myChar <= 'z'; myChar++)
                int distanceFrom_a = (int)(myChar - 'a');
                if (myChar > 'r') // 's' hangs back w/ the pqr group.
                    distanceFrom_a -= 1;
                if (myChar > 'y')  // 'z' hangs back w/ the wyz group.
                    distanceFrom_a -= 1;
                // 2 is due to the numbers starting at 2
                // 3 is due to the letters being grouped in 3's, all sharing
                // the same number.
                int number = (int)(2 + (distanceFrom_a) / 3);
                phoneHash.put(myChar, number);  // insert reg char
                // insert uppercase version, same number
                phoneHash.put(Character.toUpperCase(myChar), number);
        // convert string to a long number based on results of
        // the string's characters run through the hashmap
        public long convertStr(String s) throws IndexOutOfBoundsException
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < s.length(); i++)
                char myChar = s.charAt(i);
                if ((myChar >= 'a' && myChar <= 'z') || (myChar >= 'A' && myChar <= 'Z'))
                    sb.append(phoneHash.get(myChar));   
                else
                    throw new IndexOutOfBoundsException();
            return Long.valueOf(sb.toString());
        public static void main(String[] args)
            HashMapTester2 hmt = new HashMapTester2();
            System.out.println(hmt.convertStr("aaa"));
            System.out.println(hmt.convertStr("What"));
            System.out.println(hmt.convertStr("the"));
            System.out.println(hmt.convertStr("heck"));
            System.out.println(hmt.convertStr("Fubar"));
            System.out.println(hmt.convertStr("Snafu"));
            System.out.println(hmt.convertStr("abcdefghijklm"));
            System.out.println(hmt.convertStr("nopqrstuvwxyz"));
            System.out.println();
            System.out.println(hmt.convertStr("abc"));
            System.out.println(hmt.convertStr("def"));
            System.out.println(hmt.convertStr("ghi"));
            System.out.println(hmt.convertStr("jkl"));
            System.out.println(hmt.convertStr("mno"));
            System.out.println(hmt.convertStr("pqrs"));
            System.out.println(hmt.convertStr("tuv"));
            System.out.println(hmt.convertStr("wxyz"));
    }

  • Bug in converting string?

    I think that in Labview 5.01, the VI 'convert from exponential" is
    expected to convert strings with 0-9, E, e and . caracters into numbers.
    But it doesn't. You have to put commas (,) in your strings.
    i.e:
    3.5E-6 will be converted into 3
    3,5E-6 will be converted into 3,6E-6 (rightly)
    Does anyone already noticed that?

    See labview online help under 'VI Localization'>'Period and Comma
    Decimal Separators'. I haven't really played with the setting that this
    help topic discusses, however, it may be a good starting point for
    discovering what is going on.
    ej
    In article <[email protected]>,
    Rommeluere wrote:
    >
    > I think that in Labview 5.01, the VI 'convert from exponential" is
    > expected to convert strings with 0-9, E, e and . caracters into
    numbers.
    >
    > But it doesn't. You have to put commas (,) in your strings.
    >
    > i.e:
    > 3.5E-6 will be converted into 3
    > 3,5E-6 will be converted into 3,6E-6 (rightly)
    >
    > Does anyone already noticed that?
    >
    >
    Sent via Deja.com http://www.deja.com/
    Share what you know. Learn what you don't.

  • Not able to convert string attribute to number and date please help me out

    not able to convert string attribute to number and date attribute. While using string to date conversion it shows result as failure.As I am reading from a text file. please help me out

    Hi,
    You need to provide an example value that's failing and the date formats in the reference data you're using. It's more than likely you don't have the correct format in your ref data.
    regards,
    Nick

  • Convert String to Date and Format the Date Expression in SSRS

    Hi,
    I have a parameter used to select a month and year  string that looks like:    jun-2013
    I can convert it to a date, but what I want to do is,  when a user selects a particular month-year  (let's say "jun-2013")
    I  populate one text box with the date the user selected , and (the challenge Im having is)  I want to populate a text box next to the first text box with the month-year  2 months ahead.    So if the user selects 
    jun-2013   textbox A will show  jun-2013 
    and textbox B will show  aug-2013..
    I have tried:
    =Format(Format(CDate(Parameters!month.Value  ),  
    "MM-YYYY"  )+ 2  )   -- But this gives an error
    This returns the month in number format   like "8"    for august...
    =Format(Format(CDate(Parameters!month.Value  ), 
    "MM"  )+ 2  )
    What is the proper syntax to give me the result    in this format =  "aug-2013"  ???
    Thanks in advance.
    MC
    M Collier

    You can convert a string that represents a date to a date object using the util.scand JavaScript method, and then format a date object to a string representation using the util.printd method. For more information, see:
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.1254.html
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.1251.html
    In your case, the code would be something like:
    var sDate = "2013-01-10";
    // Convert string to date
    var oDate = util.scand("yyyy-mm-dd", sDate);
    // Convert date to new string
    var sDate2 = util.printd("mm/dd/yyyy", oDate);
    // Set a field value
    getField("date2").value = sDate2;
    The exact code you'd use depends on where you place the script and where you're getting the original date string, but this should get you started.

  • Convert String variable value  to an Object referece type

    Hi all,
    I want to know that if there any possible way to convert String variable value to a Object reference type in java. I'll explain by example if this is not clear.
    Let's think that there is a string variable name like,
    String name="HelloWorld";
    and there is a class name same to the variable value.
    class HelloWorld
    I am passing this string variable value to a method which is going to make a object of helloworld;
    new convertobj().convert("HelloWorld");
    class convertobj{
    public void convert(String name){
    // in hert it is going to create the object of HelloWorld;
    // HelloWorld hello=new HelloWorld(); just like this.
    now i want to do this from the name variable value.( name na=new name()) like wise.
    please let me know if there any possible way to do that.
    I am just passing the name of class by string variable then i wanted to make a instance of the class which come through the variable value.
    thanx.

    Either cast the object to a HelloWorld or use the reflection API (Google it) - with the reflection API you can discover what methods are available.
    Note: if you are planning to pass in various string arguments and instantiate a class which you expect to have a certain method... you should define an interface and have all of your classes that you will call in this way implement the interface (that way you're sure the class has a method of that name). You can then just cast the object to the interface type and call the method.
    John

  • How to convert string to an integer in SQL Server 2008

    Hi All,
    How to convert string to an integer in sql server,
    Input : string str="1,2,3,5"
    Output would be : 1,2,3,5
    Thanks in advance.
    Regards,
    Sunil

    No, you cannot convert to INT and get 1,2,3 BUT you can get
    1
    2
    3
    Is it ok?
    CREATE FUNCTION [dbo].[SplitString]
             @str VARCHAR(MAX)
        RETURNS @ret TABLE (token VARCHAR(MAX))
         AS
         BEGIN
        DECLARE @x XML 
        SET @x = '<t>' + REPLACE(@str, ',', '</t><t>') + '</t>'
        INSERT INTO @ret
            SELECT x.i.value('.', 'VARCHAR(MAX)') AS token
            FROM @x.nodes('//t') x(i)
        RETURN
       END
    ----Usage
    SELECT * FROM SplitString ('1,2,3')
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How to convert String (dd-MMM-yyyy) to oracle.jbo.domain.Date

    Hi
    Could you please tell how do I convert String of date in format dd-MM-yyyy to ADF date? Please show me some sample.
    Thanks

    http://javaalmanac.com/egs/java.text/FormatDateDef.html
    Once you have a java.util.Date you can convert it to oracle.jbo.domain.Date. (see http://www.fifkredit.com/bc4jdoc/rt/oracle/jbo/domain/Date.html)

  • Facing problem in converting string to date using getOANLSServices()

    I am trying to set a value for date field in my vo and trying to insert into the table.
    In controller I am getting the String which has a date:
    ex: String date="01-NOV-2007";
    while setting into the row I need to convert into Date but it is returning null.
    The below code I used
    to convert into date :
    Date dt = new Date(getOADBTransaction().getOANLSServices().stringToDate(date));
    But this dt is returning a null value is there any solution please advise me.
    Regards!
    Smarajeet

    Smarajeet ,
    See this thread, in one of my replies i have mentioned how to convert string to java.sql.date.You can use the same for oracle.jbo.domain.Date.
    urgent!How to set the default selected date for an OAMessageDateFieldBean
    --Mukul                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Converting String To XML Format and send as attachment

    Hi
    My requirement is to convert String into XML Format and that XML File i have to send as an attachment
    can any one one give solution for this Problem.
    Thank you
    Venkatesh.K

    hi,
    i m filling the itab first and converting to xml
    itab contaning these data
    GS_PERSON-CUST_ID   = '3'.
    GS_PERSON-FIRSTNAME = 'Bill'.
    GS_PERSON-LASTNAME  = 'Gates'.
    APPEND GS_PERSON TO GT_PERSON.
    GS_PERSON-CUST_ID   = '4'.
    GS_PERSON-FIRSTNAME = 'Frodo'.
    GS_PERSON-LASTNAME  = 'Baggins'.
    APPEND GS_PERSON TO GT_PERSON.
    after conversion data is coming like that
    #<?xml version="1.0" encoding="utf-16"?>
    <CUSTOMERS>
      <item>
        <customer_id>0003</customer_id>
        <first_name>Bill</first_name>
        <last_name>Gates</last_name>
      </item>
      <item>
        <customer_id>0004</customer_id>
        <first_name>Frodo</first_name>
        <last_name>Baggins</last_name>
      </item>
    </CUSTOMERS>
    but errors are  1) # is coming at the first
                            2)for 'encoding="utf-16"?>', it is not coming perfectly, some other data (iso-8859-1) should come here
    can anybody plz solve it.
    regards,
    viki

Maybe you are looking for

  • D2560 Printing too small

    I have a D2560 that I am using to print my own Certified Mail barcodes. My problem is the barcode is so small that the Post Offices scanners cannot read it. Is there a way to adjust the font in the printer to make the print larger or does the printer

  • Macbook pro went dark

    My macbook pro's screen went dead while using: safari, charge iPhone, sync iPad.  Disconnected  everything including the screen, the laptop remains dead, power supply works, neither computer no screen on laptop will boot.  Is this rest in peace time?

  • SRM and QM

    Hi, I have been asked to look into a possible implementation of SRM with QM. Does anyone have any info on this. How would this work? Thanks, AR

  • Is the intel celeron 900 good for gaming

    i got a toshiba l455 and it has intel celeron 900 and it is for world in conflict

  • Win 7 clients losing printers

    Occasionally, my Win7 client computers lose their connection with the print server (Server 2008 R2). Most of my customers  have no issues with the printers, but some (even tho they've been working fine for some time) will abruply not be able to use t