Help needed regarding Scanner class

hello
i'm really desperate for help, i'll mention that this is homework,but i need a small guidance.
i need to code a calculator,we need to use the Scanner class to break the expression to tokens(we CANNOT use other classes).
my main problem is about getting those tokens from the input string.
i tried breaking a string to tokens for hours but just couldnt do it.
a legal expression is something like:
xyzavbx1111+log(abc11*(2+5))+sin(4.5)
iilegal is : xx333aaaa111+2 or log()+2
where the alphanumerics are variables(sequence of letters followed by numbers)
i managed to get the tokens out of a string that looks like that:
String expression = "ax11111+32/3+4*2^2"
by doing:
_token = new Scanner(expression);
while(hasNext(_token)) getNextToken(_token,"\\d+(\\.\\d+)?|(\\+)|(\\-)|(\\*)|(\\/)|(\\^)|([a-zA-Z]+(\\d+));
public static boolean hasNext(Scanner s) {
return s.hasNext();
public static String getNextToken(Scanner s,String str) {
return s.findInLine(str);
but i can't get the tokens when i have sin ,cos or log in the expression
either it just ignores it or i'm looping infinitely.
my question is how can i make the regular expression include the sin log and cos?
I also know that when i'll use the "matches" method ,i'll be able to spot illegal arguments like 5//2+ because it doesnt match the pattern.
so any help conecrning the regular expression would be great thanks alot.

thx , but i already got it,after trying tons of combinations
i'll post the format i used in case someone will find this thread in the future ,while looking for something similar
the format is:
"(\\s)|(log)|(sin)|(cos)|(\\d+(\\.\\d+)?)|(\\+)"+
"|(\\-)|(\\*)|(\\/)|(\\^)|([a-zA-Z]+(\\d+))|(\\()|(\\))|(\\s)";
which includes white spaces between arguments and operators

Similar Messages

  • Help with using Scanner Class

    Hi there - I'm a newbie to Java and may have posted this in the wrong forum previously.
    I am trying to modify a program so instead of using a BufferReader, a scanner class will be used. It is basically a program to read in a name and then display the variable in a line of text.
    Being new to Java and a weak programmer, I am getting in a mess with this and missing something somewhere. I don't think I'm using scanner in the correct way.
    Any help or pointers would be good. There are 2 programs of code being used. 'Sample' and 'Run Sample'
    Thanks in advance.
    Firstly, this program will run named 'Sample'
    <code>
    * Sample.java
    * Class description and usage here.
    * Created on 15 October 2006
    package internetics;
    * @author John
    * @version 1.2
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    // import com.ralph.*;
    public class Sample extends JFrame
    implements java.awt.event.ActionListener{
    private JButton jButton1; // this button is for pressing
    private JLabel jLabel1;
    private String name;
    /** Creates new object ChooseFile */
    public Sample() {
    initComponents();
    name = "";
    selectInput();
    public Sample(String name) {
    this();
    this.name = name;
    private void initComponents() {
    Color bright = Color.red;
    jButton1 = new JButton();
    jLabel1= new JLabel();
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent evt) {
    exitForm(evt);
    getContentPane().setLayout(new java.awt.GridLayout(2, 1));
    jButton1.setBackground(Color.white);
    jButton1.setFont(new Font("Verdana", 1, 12));
    jButton1.setForeground(bright);
    jButton1.setText("Click Me!");
    jButton1.addActionListener(this);
    jLabel1.setFont(new Font("Verdana", 1, 18));
    jLabel1.setText("05975575");
    jLabel1.setOpaque(true);
    getContentPane().add(jButton1);
    getContentPane().add(jLabel1);
    pack();
    public void actionPerformed(ActionEvent evt) {
    System.out.print("Talk to me " name " : ");
    try {
    jLabel1.setText(input.readLine());
    } catch (IOException ioe) {
    jLabel1.setText("Ow! You pushed my button");
    System.err.println("IO Error: " + ioe);
    /** Exit this Application */
    private void exitForm(WindowEvent evt) {
    System.exit(0);
    /** Initialise and Scan input Stream */
    private void selectInput() {
    input = new Scanner(new InputStreamReader(System.in));
    /**int i = sc.nextInt(); */
    /** Getter for name prompt */
    public String getName() {
    return name;
    /** Setter for name prompt */
    public void setName(String name) {
    this.name = name;
    * @param args the command line arguments
    public static void main(String args[]) {
    new Sample("John").show();
    </code>
    and this is the second program called 'RunSample will run.
    <code>
    class RunSample {
    public static void main(String args[]) {
    new internetics.Sample("John").show();
    </code>

    The compiler I'm using is showing errors in these areas of the code. I've read the tutorials and still can't get it. They syntax for the scanner must be in the wrong format??
    the input.readLine appears incorrect below.
      public void actionPerformed(ActionEvent evt) {
        System.out.print("Talk to me " +name+ " : ");
        try {
            jLabel1.setText(input.readLine());
        } catch (IOException ioe) {
          jLabel1.setText("Ow! You pushed my button");
          System.err.println("IO Error: " + ioe);
        }and also here...
    the input is showing errors
      /** Initialise and Scan input Stream */
      private void selectInput() {
        input = new Scanner(new InputStreamReader(System.in));
       /**int i = sc.nextInt(); */
      }Thanks

  • Help needed regarding the updation of "Relationships" in BP

    Hello Guys,
    This is to request you to kindly help me regarding the following.
    We have a scenario where all the employees assigned to an Organizational unit (in PPOMA_CRM) are not showing in the "Relationships" ("Has Employee")in the BP transaction of that Organizational Unit.
    Could anyone let me know whether there is any update program that updates the "Relationships" from the Organizational asssignment. Or we need to enter the employees manually in BP "Relationships". Please help. Thanks in anticipation.
    Regards,
    Kishore.

    Hi Amit,
    Thanks alot for your reply. Its really helpful for me.
    So,we usually enter these relationships manually only, right? Before going ahead with the custom program, could you please let me know whether there is any SAP note related to this.Once again thanks alot for you help.
    Regards,
    Kishore.

  • Help needed regarding Segment Qualifiers

    Hi,
    In my process of implementing Apps R12 afresh, we just created the segments and assigned them their flexfield qualifiers today. In that, the one assigned towards alancing segment shows the value qualifiers like that of natural accounting segment, unlike the bal. segment value qualifier.
    I mean, when we try to insert a a value in the bal.segment it asks for qualifiers such as nature:expense/revenue/liability/asset, instead of going for the allow posting and allow budgeting alone. This is crazy, and I need your support.
    Thanks,
    Mukunthan L

    Hi Amit,
    Thanks alot for your reply. Its really helpful for me.
    So,we usually enter these relationships manually only, right? Before going ahead with the custom program, could you please let me know whether there is any SAP note related to this.Once again thanks alot for you help.
    Regards,
    Kishore.

  • Help needed Regarding Project Server - 2013 Workflow

    Hi All,
    I am new to Project server 2013 Workflow, hence please help me regarding this. Pardon me if this question is too trivial. 
    I have created a project type associated with a workflow and my workflow is as follows :
    So I am not doing anything here, I am just testing the workflow as mentioned by technet site : http://technet.microsoft.com/en-us/library/dn458865(v=office.15).aspx
    But it is mentioned that, after a minute or 2, the workflow state will change, also they have mentioned to press the Submit button.
    But in my case, the workflow is not moving to next stage [It just says 'The workflow is still processing - which never changes after hours] or I am getting the submit button (Submit button is disabled on the ribbon). Below is the state of my workflow :
    PS : I have made the user added to Portfolio managers group as well. But still I am having this same issue. 
    The Workflow manager is installed properly, and it is working fine in case of List workflow. I am facing the issue only wrt Site workflow for Project server 2013.
    Please help me to solve this issue.
    Thanks,
    shanky

    Hi Kiran,
    I am now facing issue while assigning a task to a person in the workflow.
    I am having a person named say 'John' , who is included in Project Manager as well as Portfolio Manager.
    And I am using a workflow as :
    Stage : Conceptual
    Assign a task to John (Task outcome to Variable: Outcome5 | Task ID to Variable: TaskID3 )
    Transition to stage
    Go to Approval
    But this is again giving issue as :
    Workflow Internal status : Cancelled
    Details: System.ApplicationException: HTTP 401 {"error":{"code":"-2147024891, System.UnauthorizedAccessException","message":{"lang":"en-US","value":"Access denied. You do not have
    permission to perform this action or access this resource."}}}
    PS : I have used the same Sharepoint admin account for 'Account Name' in ‘User Profile Sync' , Is this causing the issue? Please let me know.
    Thanks,
    Shanky

  • Help needed regarding BADI.

    hi all,
    can anyone plz tell me how to define BADI and how create an interface.
    plz tell from everything regarding that, i have work with basic ABAP only.
    anykind of links and any kind of matter will be helpful and you will be rewarded with points for your help difinatly.
    regards.
    raman.

    Hi Raman,
    Please search the forum and you have lots and lots of links in it. For you to start with, try these links,
    The specified item was not found.
    BADI
    Best Regards.

  • Help needed regarding font sizes

    Iam generating pdf documents using oracle developer's report builder.
    When i generate and view those pdf's using the web previewer thay appear to be quite fine,whereas when i host them on ias the font sizes gets bigger, thus lot of text gets truncated.
    Is there any parameters that has to be set for it.Pls help

    Hi Amit,
    Thanks alot for your reply. Its really helpful for me.
    So,we usually enter these relationships manually only, right? Before going ahead with the custom program, could you please let me know whether there is any SAP note related to this.Once again thanks alot for you help.
    Regards,
    Kishore.

  • Help needed regarding replication in ds5.2sp4

    Hi ,
    I am new to ldap . I am able to establish replication between master and consumer and trying to update it is getting update but i am geting the following error
    in error log
    INFORMATION - NSMMReplicationPlugin - conn=-1 op=-1 msgId=-1 - Replication bind to consumer alpha.ad.com:19941 failed:
    [16/May/2007:13:48:26 -0700] - INFORMATION - NSMMReplicationPlugin - conn=-1 op=-1 msgId=-1 - Failed to connect to replication consumer alpha.ad.com:19941
    [16/May/2007:13:48:26 -0700] - ERROR<8318> - Repl. Transport - conn=-1 op=-1 msgId=-1 - [S] Bind failed with response: Failed to bind to remote (900).
    Please help me regarding this .
    Message was edited by:
    ap7926

    If data is getting replicated from master to consumer then the bind for that specific replication agreement is working.
    Check your timestamps and current log entries. Are the "Failed to connect to replication" messages currently being generated? As long as your replication agreement is enabled the supplier will try to keep things up and running, retrying a failed consumer regularly (and generating about 1 set of log messaages per minute on my systems). So you'll get those messages on the supplier when a good consumer is down (the nsslapd directory server process that is).
    If you don't have these messages being generated currently then this probably means that your consumer was down around "16/May/2007:13:48:26 -0700" but is ok now. In that case those messages aren't of big concern. They're just telling you that you had a problem, which you hopefully already knew about.
    If replication is working (test by making a change on the supplier and checking it on the consumer) AND you're still concurrently getting these messages regularly then you have something interesting going on, probably due to a configuration issue. Without seeing the details it's difficult say what it would be.

  • Help needed regarding JNI library

    Hi all,
    I m developing a JNI application on windows in which my paint function is native and in it I m passing an array of String.
    public native void paint(String[] arr);
    and in native library my code is
    JNIEXPORT void JNICALL Java_Hello_paint
    (JNIEnv *env, jobject canvas, jobjectArray arr)
    MessageBox(NULL,"JNI start",NULL,NULL);
    The problem is that both these codes compile without any error and also run without giving any error but it does not give the messagebox.
    Can any one help?

    Our main class is Hello
    This class is extended from Canvas.
    public class Hello extends Canvas {
    static String[] arr = {"Abc"};
    static {
    System.load("C:/a/a.dll");
    public native void paint(Graphics g);
    public static void main(String[] args) {
         In this method we are making a frame, adding a panel on it and then adding a Canvas on the panel.
         When we mAke this frame visible then paint is called.
         And this paint in the native C code draws some image.
    Then we compile it and generate a Hello.h file using javah and then use it in our c file.
    In .h file the format is like this
    JNIEXPORT void JNICALL Java_Hello_paint
    (JNIEnv *, jobject, jobject);
    Now in C file
    JNIEXPORT void JNICALL Java_Hello_paint
    (JNIEnv *env, jobject canvas, jobject graphics)
         MessageBox(NULL,"JNI start",NULL,NULL);
    This works without any problems
    Now if I do the following in Hello.java file
    public native void paint(Graphics g,String[] arr);
    In Hello.h I get
    JNIEXPORT void JNICALL Java_Hello_paint
    (JNIEnv *, jobject,jobject ,jobjectArray);
    and in C file
    JNIEXPORT void JNICALL Java_Hello_paint
    (JNIEnv *env, jobject canvas, jobject graphics, jobjectArray arr)
         MessageBox(NULL,"JNI start",NULL,NULL);
    Then it does not show any error in compilation or runtime but it does not display the Message Box
    Thanks
    Arun

  • Help Needed regarding Mandatory Field.

    Hi All,
    I have requirement that i have to make certain feilds mandatory in my WD4A view. I have made the "state" property of the fields(input element) as "required". Then i tried doing an event on the view to check whether it throws an error, stating mandatory fields are blank, but i dint get any message.
    Please help me to understand whether what i did is suffice or i need to handle the mandatory concept through my code.
    Thanks,
    Selvakumar M.,

    Hi Selva,
    You need to call the static method check_mandatory_attr_on_view of class cl_wd_dynamic_tool. This would then automatically verify if all the mandatory fields have been filled or not. It would then populate the error messages into an internal table and display them in the view. Also the mandatory fields which haven't been filled would be highlighted with a red border. You need to put the below coding into the action up on which you want to trigger the data chesks.
    data: lt_msg TYPE cl_wd_dynamic_tool=>t_check_result_message_tab,
              lo_view_controller TYPE REF TO if_wd_view_controller,
              lo_message_manager type ref to if_wd_message_manager.
      lo_view_controller ?= wd_this->wd_get_api( ).
      lo_message_manager = lo_view_controller->get_message_manager( ).
      cl_wd_dynamic_tool=>check_mandatory_attr_on_view(
        EXPORTING
          view_controller = lo_view_controller
          display_messages = abap_true
        IMPORTING
          messages = lt_msg ).
    Regards,
    Uday

  • Help needed regarding the client server communication

    this is regarding my networking project which at present i am doing it in java...
    the project is abt establishing a server in my lab that controls all the other systems in that lab... now the problem is i have to shut down all the systems in the lab from the server on a click of a button.... this i need to do using socket programming to which i am new....
    So can anyone pls send me a sample code as to how to pass a command from server to shut shut down all the systems(clients) ..i need a java program that uses sockets concept to perform the above mentioned operation...pls note i am trying to establish a linux server
    regards
    lalita

    Dear hiwa
    i can use it but the constraint in my project is to use only the Socket programming due to time lacks.... i have to find a faster way to communicate between the server and the client...
    can u pls help me find a solution for this via sockets...
    hoping a favorable response
    regards
    Lalita

  • Help needed Regarding a business logic

    Hi all,
    My business requirement is
    requires to get a checksum from the KIOSK field. This would be something like a rule that for a given KIOSK generates a number from 0 to 9.
    The Field value contains alphanumerical
    Can any of guys help me in this logic.how to generate a checksum for a given field..
    Thanks & Regards;
    Vinit

    Alright I found something  I am not  sure if it is of use to you , A checksum is generally used to  detect the integrity of file
    it is calculated oin basis of hash algorithms so  how it is useful to for incoming filed values i m not  sure
    Please find the links below
    http://en.wikipedia.org/wiki/Checksum
    http://www.fastsum.com/support/online-help/checksums.php
    http://www.flounder.com/checksum.htm
    http://www.mkyong.com/java/how-to-generate-a-file-checksum-value-in-java/
    If it is useful , you need to implement a hash algorithm
    regards
    Ninad

  • Help needed regarding SUM keyword in an ITAB loop

    Hello,
    I am maintaining a code as given below.
    LOOP AT itab INTO totwa.
    SUM.
    ENDLOOP.
    totwa is defined as a workarea which is needed to hold the sum totals of the fields in the itab. According to the documentation of SUM, it should calculate the sum totals and should put the totals in the workarea mentioned. But somehow its not calculating the value. Could anyone please help me in resolving this issue. Please guide me with your thoughts as to what might have gone wrong.
    Note: the itab fields are of type P.
    Thanks in advance
    Sudha Naik

    Hello Suha
    According to the ABAP documentation the SUM statement is used in a specific situation:
    <b>Syntax
    SUM. </b>
    <b>Effect </b>
    <i>The statement SUM can only be specified within a loop starting with LOOP, and is only considered within a AT-ENDAT control structure. Prerequisites for using the statement SUM include using the addition INTO in the LOOP statement, and that the specified work area wa is compatible with the row type of the internal table. In addition, SUM cannot be used when the row type of the internal table itab contains components that are tables. </i>
    <i>The statement SUM calculates the component total with the numeric data type ( i, p, f) of all rows in the current control level and assigns these to the components of the work area wa. In the control levels FIRST, LAST , and outside of an AT-ENDAT control structure, the system calculates the sum of numeric components of all rows in the internal table.</i>
    I hope the following sample report will clarify the use of <b>SUM </b>and <b>COLLECT</b>.
    *& Report  ZUS_SDN_COLLECT
    REPORT  zus_sdn_collect.
    TYPES: BEGIN OF ty_s_line.
    TYPES:   key(1)    TYPE n.
    TYPES:   value     TYPE p DECIMALS 2.
    TYPES: END OF ty_s_line.
    TYPES: ty_t_itab    TYPE STANDARD TABLE OF ty_s_line
                        WITH DEFAULT KEY.
    DATA:
      gs_line       TYPE ty_s_line,
      gt_itab       TYPE ty_t_itab,
      gt_itab_coll  TYPE ty_t_itab.
    START-OF-SELECTION.
      DO 3 TIMES.
        gs_line-key = syst-index.
        gs_line-value = syst-index * '2.3'.
        APPEND gs_line TO gt_itab.
        APPEND gs_line TO gt_itab.
      ENDDO.
      gs_line-key = 4.
      gs_line-value = '5.5'.
      APPEND gs_line TO gt_itab.
      WRITE: / 'Initial list'.
      LOOP AT gt_itab INTO gs_line.
        WRITE: / gs_line-key,
                 gs_line-value.
      ENDLOOP.
      WRITE: / syst-uline.
      SKIP 2.
      WRITE: / 'Using SUM statement with AT END OF'.
      SORT gt_itab BY key.
      LOOP AT gt_itab INTO gs_line.
        AT END OF key.
          SUM.
          WRITE: / gs_line-key,
                   gs_line-value.
        ENDAT.
      ENDLOOP.
      WRITE: / syst-uline.
      SKIP 2.
      WRITE: / 'Using SUM statement without control structure (1)'.
      SORT gt_itab BY key.
      LOOP AT gt_itab INTO gs_line.
        SUM.
        WRITE: / gs_line-key,
                 gs_line-value.
      ENDLOOP.
      WRITE: / syst-uline.
      SKIP 2.
      WRITE: / 'Using SUM statement without control structure (2)'.
      SORT gt_itab BY key.
      LOOP AT gt_itab INTO gs_line.
        SUM.
        WRITE: / gs_line-key,
                 gs_line-value.
        EXIT.
      ENDLOOP.
      WRITE: / syst-uline.
      SKIP 2.
      WRITE: / 'Using COLLECT statement'.
      REFRESH: gt_itab_coll.
      LOOP AT gt_itab INTO gs_line.
        COLLECT gs_line INTO gt_itab_coll.
      ENDLOOP.
      LOOP AT gt_itab_coll INTO gs_line.
        WRITE: / gs_line-key,
                 gs_line-value.
      ENDLOOP.
      WRITE: / syst-uline.
      SKIP 2.
      WRITE: / 'Using COLLECT statement for total sum'.
      REFRESH: gt_itab_coll.
      LOOP AT gt_itab INTO gs_line.
        gs_line-key = 0.
        COLLECT gs_line INTO gt_itab_coll.
      ENDLOOP.
      LOOP AT gt_itab_coll INTO gs_line.
        WRITE: / gs_line-key,
                 gs_line-value.
      ENDLOOP.
      WRITE: / syst-uline.
      SKIP 2.
    END-OF-SELECTION.
    Regards
      Uwe

  • Help needed regarding the deployment architecture for PROD env

    Dear All,
    Please help me with some clarifications regarding the deployment architecture for PROD env.
    As of now I have 2 single node 12.1.1 installations for DEV and CRP/TEST respectively.
    Shortly I will be having a PROD env of 12.1.1 with one DB node and 2 middle tier (apps) node. I need help in whether -
    1) to have a shared APPL_TOP in the SAN for the 2 apps node or to have seperate APPL_TOPs for the 2 apps node. The point is that which will be benificitial in my case from business point of view. The INST_TOPS will be node specific in any case right?
    2) Where to enable the Concurrent Managers, in the DB node or in the primary apps node or in 2 apps node both for better performance.
    12.1.1 is installed in RHEL 5.3
    Thanks and Regards

    Hi,
    Please refer to (Note: 384248.1 - Sharing The Application Tier File System in Oracle E-Business Suite Release 12).
    For enabling the CM, it depends on what resources you have on each server. I would recommend you install it on the the application tier node, and leave the database installed on one server with no application services (if possible).
    Regards,
    Hussein

  • Help needed regarding BADI in SAP-CRM 2007.

    hi all,
    i need some help regarding BADI for new creation and enhancement.
    plz help, you will be rewarded accordingly.
    regards.
    raman.

    Hi Raman,
    visit this link
    http://help.sap.com/saphelp_nw70/helpdata/en/32/a83942424dac04e10000000a1550b0/content.htm
    http://help.sap.com/saphelp_crm40/helpdata/en/c3/69bf4abf1045e0966badb60d6160dd/content.htm
    Regards
    Anup.

Maybe you are looking for

  • Error message in SDS report shipping processing

    Hello everybody, we are running a SAP ECC 6.00 system with EA-APPL 15. We are using the standard SDS shipping process of inbound documents triggered by delivery. Everything worked fine, but all of a sudden each SD_CALL gets an error message in CVD1 i

  • Java Signing issues when loading web start app

    Hey, not sure if this is the correct place for this - but couldn't think where else to put it... I'm a bit stuck at the moment and i wondered if anyone could shed some light on my problem, and where I might go from here. We've developed a EJB3 applic

  • How to get Personnel Numbers from Organizational Unit ?

    Hello All, I have a requirement in the HR module to get a list of all the personnel numbers maintained for a Organizational Unit. Is there any Function Module to find out the Personnel Numbers assigned to a Organizational Unit for HR module ? Thanks,

  • Premiere Pro CC 2014 encoding issues due to graphic opacity settings?

    Our marketing team has been working on some instructional video content in Premiere Pro CC 2014 and have encountered issues with encoding the completed sequences. Our output format is HD video with the H.264 codec, 1920 x 1080, 30 FPS. The symptom of

  • Dell SB Live 5.1 used in another desk

    I am having serious problems trying to use my dell SB Li've card in another computer, in particular with the MIDI. I connected the MIDI output to a keyboard, and usually an icon in Sonar, a music editing software, tells me if it recognizes when the k