How to return a message in a boolean method?

I am looking to return a message other than true or false using a boolean method. Is that possible to do without displaying the true, or false?
private boolean search(Node node, int id){
          if (node == null)
               return false;
          else if (id == node.id){
               return true;
          else if (id < node.id){
               return search(node.left, id);
          else
               return search(node.right, id);
     }In this snippet I would like to return a message rather than true or false.
My idea was to put the println statement just before the return, but that leaves me with a true or false being displayed.
I also thought i could use an if statement in my main:
public class studentTest {
     public static void main(String[] args) {
          StudentDatabase data = new StudentDatabase();
          System.out.println(data.insert(7066, "Pianczk", 25, 4.0));
          System.out.println(data.insert(7067, "Pianczk", 25, 4.0));
          data.insert(756, "Pia", 78, 3.5);
          boolean result;
          result = data.search(7066);
          if (result){
               System.out.print("")
}the problem with this is I can't reach the info I would like to print out.(or at least I don't know how)

I figured it out.
I thought I tried this once already, but must not have done it correctly.
private boolean search(Node node, int id){
          if (node == null){
               return false;
          else if (id == node.id){
               System.out.print("Student info: " + node.id + " " + node.lastName + " " + node.age + " " + node.gpa);
               return true;
          else if (id < node.id){
               return search(node.left, id);
          else
               return search(node.right, id);
public static void main(String[] args) {
          StudentDatabase data = new StudentDatabase();
          System.out.println(data.insert(7066, "Pianczk", 25, 4.0));
          System.out.println(data.insert(7067, "Pianczk", 25, 4.0));
          data.insert(756, "Pianc", 78, 3.5);
          int id = 7065;
          boolean result;
          result = data.search(id);
          if (result)
               System.out.println("");
          else
               System.out.print("Your ID " + id + " was not found");
}this works, although I am not sure if this is the optimal way of doing it.

Similar Messages

  • How to return the message in MTI and bitmap?

    Here we receive xml message from client but the problem is this coding is for the first time it receive MTI message, so how can i do if i receive from client in xml type then convert to MTI then response it as xml again to client.
    Is it too hard to understand?????
         * Waits and receive an ISOMsg over the TCP/IP session
         * @return the Message received
         * @exception IOException
         * @exception ISOException
        public ISOMsg receive() throws IOException, ISOException {
            byte[] b=null;
            byte[] header=null;
            LogEvent evt = new LogEvent (this, "receive");
            ISOMsg m = createMsg ();
            Socket socket = getSocket();
            m.setSource (this);
            try {
                if (!isConnected())
                    throw new ISOException ("unconnected ISOChannel");
                synchronized (serverIn) {//read byte/array of byte
                    int len  = getMessageLength();
                    int hLen = getHeaderLength();
                    if (len == -1) {
                        if (hLen > 0) {
                            header = readHeader(hLen);//read in message header
                        b = streamReceive();
                    else if (len > 0 && len <= 10000) {
                        if (hLen > 0) {
                            // ignore message header (TPDU)
                            // Note header length is not necessarily equal to hLen (see VAPChannel)
                            header = readHeader(hLen);//header lenght read the message header
                            len -= header.length;
                        b = new byte[len];
                        serverIn.readFully(b, 0, len);//get the input from user with byte type,0 length into lenght,read the byte to server in.
                        getMessageTrailler();  
                    else
                        throw new ISOException(
                            "receive length " +len + " seems strange");
                *// TODO:*
    *         // prefix with standard ISO MTI and bitmap*
                *// using ISOMsg setters*
                m.setPackager (getDynamicPackager(b));//msg receive
                m.setHeader (getDynamicHeader(header));
                if (b.length > 0 && !shouldIgnore (header))  // Ignore NULL messages
                    m.unpack (b);//raw message
                m.setDirection(ISOMsg.INCOMING);//set the direction for incoming msg into isoMsg
                m = applyIncomingFilters (m, header, b, evt);//remove the incoming filter to isoMsg
                m.setDirection(ISOMsg.INCOMING);
                evt.addMessage (m);
                cnt[RX]++;
                setChanged();
                notifyObservers(m);
           catch {
            return m;
        }

    check this link, and use as per you requirement
    XI: How-to on JDBC receiver response
    JDBC Receiver Adapter -- Synchronous Select – Step by Step
    Regards
    Chilla

  • (newbie) How to return error messages to JSP page.

    Hello,
    I'm using a very simple Model 1 architecture (no framework such as Struts used.) The webapp just consists of a login.jsp which collects database connection parameters and then activates a servlet to return a PDF report to the browser.
    I have a very common need: I would like the errors entered by the user on the login.jsp to be displayed at the top of a new return of the login.jsp (with the bottom of the JSP still providing the edit fields for reentry), errors such as:
    1.) User did not enter the username, password, and database name
    2.) Having a wrong username/password for the given database.
    (2) is more complex than (1), because it would involve feedback from the servlet (which makes the DB connection).
    I'm not sure how to code this, however, with just JSP, JSTL and JavaBeans. Does anyone know of an example with source code on the web where something similar to this is done?
    Thanks,
    Glen

    No problem on posting here. Seeing as JSP forum is not accessible, this is the next best choice.
    What sort of complexity are you after here?
    You can go with the very simple:
    Print out the error messages as you discover them.
    if (request.getParameter("username") == null){
      // print out the message
      out.println("Please enter your username");
      // or alternatively
      List errors = new ArrayList();
      errors.add("Please enter your username");
    }The best way to get feedback is to write your login method to return whether login succeeded or not. That can be a boolean true/false value, or you could return a User object to indicate success, and null to indicate failure.
    How much of the code is in servlet, how much in JSP?

  • How to return error message using macro or others ways

    Hi !
    I need your help to find a technical solution.
    We have an alv object with 2 parameters (a checkbox and a writable field which is for address mail.) When you push the button B1, the function module SX_INTERNET_ADDRESS_TO_NORMAL is called to verify the email address.
    If I use the classic way to show the exceptions returned by the function module, the user can read the message but when he does an action on the program this dump. (The program has been killed.)
    I am looking for a way to show the error message and the possibility to change the email address. I think that using a popup information would work but I do not find this way very nice. Can I use macro to have the message on the status? In positive case, could you explain me how to use it?
    Thanks!

    check the context in which the message statement is running, [here in sap library - message processing|http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/dbaae335c111d1829f0000e829fbfe/frameset.htm], you will get the answer why!

  • How to return multiple values from a getProperty method

    Hi All,
    Even though I understand that getPropprty can return only one value. I just have a doubt. Is it possible to use a getProperty method of a bean like
    public String getemp_Info(){
    return emp_Id;
    return emp_Name;
    }also can any one explain me where and how to use private variables and public variables in a bean.
    R.Ramesh.

    I already have it I just wanted to know that is there any usage like the one I asked, anyway thanks for your suggestion.
    I have already used another getProperty method as balusc quoted.

  • How to Customize the Message "No Row Returned" from a Report

    Hi,
    I've been trying to customize the Message "No Row Returned" from a Report.
    First i followed the instructions in Note:183131.1 -
    How to Customize the Message "No Row Returned" from a Report
    But of course the OWA_UTIL.REDIRECT_URL in this solution did not work (in a portlet) and i found the metalink document 228620.1 which described how to fix it.
    So i followed the "fix" in the document above and now my output is,..
    "Portlet 38,70711 responded with content-type text/plain when the client was requesting content-type text/html"
    So i search in Metalink for the above and come up with,...
    Bug 3548276 PORTLET X,Y RESPONDED WITH CONTENT-TYPE TEXT/PLAIN INSTEAD OF TEXT/HTML
    And i've read it and read it and read it and read it and can't make heads or tails of what it's saying.
    Every "solution" seems to cause another problem that i have to fix. And all i want to do is customize the Message "No Row Returned" from a Report. Please,...does anyone know how to do this?

    My guess is that it only shows the number of rows it has retrieved. I believe the defailt is for it to only retrieve 50 rows and as you page through your report it retrieves more. So this would just tell you how many rows was retireved, but probably not how many rows the report would contain if you pages to the end. Oracle doesn't really have a notion of total number of rows until the whole result set has been materialized.

  • How to Fix ''The messaging interface has returned an unknown error. If the problem persists, restart Outlook.' Error

    How to Fix ''The messaging interface has returned an unknown error. If the problem persists, restart Outlook.' Error, user has outlook 2007 connected to exchange 2010 server , I tried scan pst, configuring new profile but no luck so far. Please suggest !
    Aditya Mediratta

    Hi,
    Please try the steps mentioned below and check if it helps:
    Open Computer > Local Disk C > Program Files > Microsoft Office > Office 12 > Outlook.exe.
    Right click on outlook.exe and click on Properties and then click on
    Compatibility tab. Uncheck the box ‘run this program in compatibility mode for’ under compatibility mode, click on Apply and OK.
    Note: If you are using 64 bit computer then the file location of the file will be
    Computer>Local Disk C>Program Files (x86) >Microsoft Office>Office 12>Outlook.exe
    Similar thread:
    https://social.technet.microsoft.com/Forums/en-US/aa396c9e-0ce5-4de5-99e3-4f0d771b07e0/exchange-2007-messaging-interface-has-returned-an-unknown-error
    Best Regards.

  • TS1424 How do you fix a R6025 pure virtual function call error?  When I try to search for music, iTunes freezes & returns this message.

    How do you fix a R6025 pure virtual function call error?  When I try to search for music, iTunes freezes & returns this message.

    For general advice see Troubleshooting issues with iTunes for Windows updates.
    The steps in the second box are a guide to removing everything related to iTunes and then rebuilding it which is often a good starting point unless the symptoms indicate a more specific approach. Review the other boxes and the list of support documents further down page in case one of them applies.
    Your library should be unaffected by these steps but there is backup and recovery advice elsewhere in the user tip.
    tt2

  • How to validate and return error message

    JDev 9.0.5.2 ADF UIX and Struts
    Scenario:
    I have a uix input page with 2 view objects (VO1-updates an entity object, VO2-sql viewobject, no entity).
    I have a Save button and its event where I want to handle the validation check and then commit the data. I need to manually check the VO2 fields in java and if none of them are populated, I need to stay on the same page and return a message. If one of the fields is populated, I need to save the data in VO1 and insert the values in VO2 into a table using java.
    I have been looking at the dataForwardAction class for the page but I am not sure if I should be overriding methods and which ones, as well as how to remain on the page if VO2 does not have at least 1 value populated with a message to the user.
    Any help is greatly appreciated.

    Hmm, I believe while, ActionError.GLOBAL_ERROR is a static string variable, it is used to hold the value that identifies the global error properties. I know I add multiple errors to global errors. Regardless, instead of ActionErrors.GLOBAL_ERROR you can use your own property, such as "test". Then on your jsp page you can use this tag: <html:errors property="test"/> and it should pull the relevant action error information. The value "context.errors.password.bad" by the way refers to a value in your ApplicationResources.properties file or whatever message resource file you have designated in your struts config as default.

  • How to return data from message bean ? ? ?

    Hi ... I have developed one simple application in JMS ...
    I have created one jsp page, one message bean and one remote EJB ...
    Now i m sending message to message bean .... i m also receiving message in message bean and i m calling one simple EJB method on that message called ...
    This all things are working well. But i wanted to return some data from that EJB to my JSP page .
    for example ...
    there is one sayHello() method in EJB which i m calling from message bean as i got message from JSP page .
    if i m printing that string in server log than its working well .
    now i wanted to return that string from that EJB method to JSP page.
    How can i achieve this ? can any one help me please ...
    actually i wanted to return whole XML file but recently as a newbie i m trying to just return hello world string .
    please help me for this problem ....
    thnks ...

    if you want to return a result, then you probably shouldn't be using a message bean. message beans for for asynchronous tasks. session beans for for synchronous tasks. thus it would make much more sense to have your jsp call the session bean directly.

  • How to fetch Error message

    Hi folks,
    I am new to c/c++.
    And i am finding it difficult to figure it out ..............
    char* APIParser::parseDocument(const char *xmlInput) {
              XMLParser parser;
              const char *doc;
              uword ecode;
              doc = xmlInput;
              if(doc == NULL)
    //Return XML output
                   return getDefaultXMLOutput(-1, 0, "XML input document is null");
              if (ecode = parser.xmlinit()) {
                   cout << "Failed to initialize XML parser, error " << ecode;
                   //return ecode;
                   return getDefaultXMLOutput(-1, 0, "Failed to initialize XML parser");
              if (ecode = parser.xmlparseBuffer((oratext *) doc, strlen(xmlInput), (oratext *) 0,
                   XML_FLAG_DISCARD_WHITESPACE)) {
                   cout << "Parse failed, error " << ecode << "\n";
                   //          return 3;
                   return getDefaultXMLOutput(-1, 0, "Parse failed");
              if (ecode = schema.initialize(&parser))     {
                   cout << "Failed, code " << ecode << "!\n";
                   //return 4;
                   return getDefaultXMLOutput(-1, 0, "Error in initialize Schema");
              root = parser.getDocumentElement();
              if (ecode = schema.validate(root, NULL )){
                   cout << "Validation failed, error " << ecode << "\n";
                   ub4* ub4;
                   unsigned char** path;
                   int i=0;
                   boolean value;
                   while((value = parser.xmlwhere(ub4, path, i++))){
                        cout<<ub4<<endl;
                        cout<<ub4<<path;
                   cout<<value;
                   schema.terminate();
                   //return 5;
                   return getDefaultXMLOutput(-1, 0, "Validation failed");
              return "";
    Where i am passing xmlInput which is a char*.
    Things work fine.
    I need to send back exact error message to client to debug the messages.
    How to fetch the messages, line number etc.
    By seing docs i wont be able to figure it out.
    Can any one send piece of code to fetch the error messages.

    If you access the FacesContext you find a method called
    getMessages()
    Return an Iterator over the FacesMessages that have been queued, whether or not they are associated with any specific client identifier.

  • After upgrading to Lion the bookmarks in Preview returns error message.

    After upgrading to Lion the bookmarks in Preview returns error message : The File "****" couldn't be opened because you don't have permission to view it. To change the perimssion, select the item in finder and Choose File info.  I have bookmarked plenty of files in Preview.  How to overcome this error message???

    Doesn't work Steve. I think it is an issue with Preview being sandboxed (check the sandbox column in Activity Monitor: Preview = Yes). Sandboxed apps restrict file access to those the user has explicitly selected. My theory is that this causes the unfortunate side effect of bookmarked or linked PDFs not working. A simple test: open a file with bookmarks, manually open the bookmarked file and then select the bookmark in the first file - it should open with no complaints about permissions (which leads to a weak workaround: open all the PDFs you intend to work with!).

  • How to print error messages in browser?

    When I visit a jsp file in browser, there's some errors in the jsp file, so the browser returns
    The page cannot be displayed
    There is a problem with the page you are trying to reach and it cannot be displayed.
    I want the detail error messages, so I can debug my problem. How to print error message in browser or find the message in some log file?

    Hi Kanaraja,
    Thanks for your answer. I need to get certain information from the list. So, I use LIST_To_ASCII FM. However, may I know the ascii_tab should be type to what? And after this FM, do I have to use another FM to display the ascii list?
    data ABAPLIST type ABAPLIST OCCURS 0.
    SUBMIT  RPCALCU0 VIA SELECTION-SCREEN
    with PNPXABKR = 'US'
    with PNPTIMRA = 'X'
    with PNPPABRP = '10'
    with PNPPABRJ = '2003'
    with PNPPERNR-LOW = '100750'
    with PNPPERNR-LOW = '109202'
    with PNPPERNR-LOW = '100255'
    with PNPABKRS-LOW = 'US'
    with SCHEMA = 'ZUSP'
    with RADI_EDT ='X'
    with EDT_VARI = 'CUS&SAP_US'
    with TST_ON = 'X'
    EXPORTING LIST TO MEMORY and RETURN.
    CALL FUNCTION 'LIST_FROM_MEMORY'
      TABLES
        listobject       = ABAPLIST
    EXCEPTIONS
       NOT_FOUND        = 1
       OTHERS           = 2.
    CALL FUNCTION 'LIST_TO_ASCI'
      EXPORTING
        list_index         = -1
      TABLES
        listasci           = asci_tab
        listobject         = ABAPLIST
      EXCEPTIONS
        empty_list         = 1
        list_index_invalid = 2
        OTHERS             = 3.
    IF sy-subrc NE '0'.
      WRITE:/ 'LIST_TO_ASCI error !! ', sy-subrc.
    ENDIF.

  • How to display a message in an audit report?

    hello all,
    i would like to ask how do display a message in an audit report.  here is my code...
    CALL TRANSACTION tcode USING i_bdcdata
                            MODE c_n
                            MESSAGES INTO i_error2.
    IF sy-subrc EQ 0.
    ENDIF.
    CLEAR i_error2.
    LOOP AT i_error2.
      IF i_error2-msgtyp EQ c_e.
        MOVE v_pernr TO i_bdcerror2-pernr.
        MOVE c_infotype TO i_bdcerror2-infty.
        MOVE 'Error' TO i_bdcerror2-msgtype.
    <b>    SELECT SINGLE text
          INTO v_msgtxt
          FROM t100
          WHERE sprsl = i_error2-msgspra
          AND arbgb = i_error2-msgid
          AND msgnr = i_error2-msgnr.
        MOVE v_msgtxt TO i_bdcerror2-msgtxt.</b>
        APPEND i_bdcerror2.
      ENDIF.
    ENDLOOP.
    DESCRIBE TABLE i_bdcerror LINES v_bdcerrors.
    IF v_bdcerrors <> 0.
      SKIP 1.
      WRITE: 'BDC Error Report'.
      SKIP 1.
      WRITE: 'PERNR',
             'INFOTYPE',
             'MESSAGE TYPE',
             'MESSAGE TEXT'.
      ULINE.
      LOOP AT i_bdcerror.
        WRITE: / i_bdcerror-pernr,
               13 i_bdcerror-infty,
               22 i_bdcerror-msgtype,
               35 <b>i_bdcerror-msgtxt</b>.
      ENDLOOP.
    ENDIF.
    the message text that i was getting contains &1, &2 and so on.  how would i be able to replace it with the original value?
    thanks!
    -ann

    After calling the transaction, this is what I do.
    a) Call the function module, <b>MESSAGE_TEXT_BUILD</b> and pass the following values from <b>BDCMSGCOLL</b> or the internal table where you collect the messages.
       i) MSGID
      ii) MSGNR
    iii) MSGV1
      iv) MSGV2
       v) MSGV3
      vi) MSGV4
    There is no need to fetch data using select from table t100.
    It builds the message and returns in MESSAGE_TEXT_OUTPUT which can be then displayed to user.
    Regards,
    Subramanian V.

  • How to display success message in function module

    Hi Experts,
                      I am developing new function module regarding URL finder. As per my requirement ,
                                                 If USER ID is not provided -display SUCCESS MESSAGE and Provide sy-uname.
    how to display success message.if possible can You write the code.
    Thanks
    raju

    Hello,
    We can use an exporting parameter like single character field like 'S' for success and 'E' for error instead of a message.
    Another option is you can use the Tables parameter and populate Return table with error or success message. Return table of type 'BAPIRET2'.
    Hope this might help you!
    Regards,
    MM Jaffer.

Maybe you are looking for

  • Unable to create titles, getting "Out of memory" error message

    I am editing a project on FCE 2.0.3. I recently re-opened the project after about a year. It is stored on a 500GB external firewire hard-drive. I am working on a Mac G5 Powermac 7.2 with OS 10.4.11 with 1GB of RAM. I have my system settings on FCE se

  • Mail with multiple gmail accounts sending messages from wrong email, other than the one i select

    mail with multiple gmail accounts sending messages from wrong email, other than the one i select: i'm using mail on osx 10.7 with multiple gmail accounts. when i create an email, i check to be sure i'm sending/replying from the correct account. after

  • Configuration steps to integrate javaSSO & OBIEE

    Hi, Environment: OAS,javaSSO,OBIEE I'm trying to implement javaSSO(from OAS) for BI Presentation(OBIEE) I just want to know how to configure OBIEE and javaSSO. I have gone through several forums and blogs to configure OAS javaSSO and OBIEE but was un

  • Cluess: Want to create soundtrack for video

    Here's my goal: I want to download a home movie from DVD and write a musical soundtrack for it. I would also like to download an old silent movie and do the same. Old silents are, I believe, in the public domain and should not risk copyright infringe

  • Question on Flex Component

    Hi, I have two components and i am trying to display pre-defined component1 state from component2 when a button is clicked. My Code in Component2 to acheive this: private function displayComponent1():void      var comp1:Component1;      comp1.current