String.  Relational operator and odd printing

Hi,
I'm wondering if someone could help me with this puzzlement I have. I've search the forum and I search the tutorial with "string and relation operator" and "string and compare" but I couldn't find any answer.
Basically, I want to make sure that we can't use "<", ">", ">=", and "<=" between two strings because I got compiler error. Tutorial only says to use equals() method but I can't find anything that says "Don't use relational operator such as... !"
Another question I have is I have this test code just to know String more.
<code>
public class Test {
static void compare (String s1, String s2) {
System.out.println ("s1 is = " + s1);
System.out.println ("s2 is = " + s2);
System.out.println (s1 + " == " + s2 + s1==s2); //this line prints "false"
System.out.println (s1 + " != " + s2 + s1!=s2); //this line prints "true"
System.out.println ("s1.equals(s2): " + s1.equals(s2));
public static void main (String args[]) {
compare ("Hello", "huhaha");
compare ("Hello", "hello");
compare ("Hello", "Hello");
</code>
I'm wondering why the line that I commented prints "false" and "true" where I expected to print the value of s1 which is "Hello" and s2 which is "huhaha"?
Sorry if the question seems stupid. I do admit I'm a little slow.
Thank you!

This question is asked all the time on this forum.
Basically, the "==" operator between any two Objects (Strings included) is comparing instances. That is, are the two Objects references to the same "real" instance? If so, it will return true. However, just because two Strings contain the same value does not mean they are the exact same instance. So two different strings which contain the value "XXX" could still have "==" return false. For this reason, it is recommended that (in general) you use "==" and "!=" as it relates to Objects only when comparing them to null (there is only one null).
Instead, use the "equals()" method. There are no "<", "<=", ">", or ">=" operators in relation to Objects. Instead, use the Object's compare() method, if available (which it is for Strings).

Similar Messages

  • Load String into CharArray and then Print String in Reverse?

    Hey, what would the code be to:
    1. Ask user for name. (scanner)
    2. Load his name into a CharArray.
    3. Then print out his name backwards.
    thanks a lot!

    dforevergold has a head on his neck. So, I don't understand people saying about assignments etc... If he needs help and we can help then we must help.
    Here's the code (but don't forget about comments!):
    import java.util.Scanner;
    public class Just {
         public static void main(String[] args) {
              // a scanner to get user's input
              Scanner scan = new Scanner(System.in);
              // Scanner.nextLine() returns the entered line
              String name = scan.nextLine();
              // toCharArray() converts a 'String' object to a 'char[]' object
              char[] ch = name.toCharArray();
              // next FOR-loop goes from the last element in the array to the first one and prints them onscreen
              for (int i = ch.length - 1; i >= 0; --i) System.out.print(ch);
    I hope it helps you!
    Yours Sincerely,
    Nikaustr

  • How to use string relational operator.

    Hi,
    In my program,I have one 'Period' select option,having string length '3', I want only number should be entered in this select option,if user enter other than number any value then it should show an error message.
    currently I am using 'CA' operator but problem in this is that out of  '3' if any one contain number then instead of getting error message i am getting short dump.for it is giving error message if all '3' character are alphabet.
    e.g.: 1. If Period = 388,   working fine.
          2. If period = ABC,   Getting error message.
          3. If period = p18,   getting short dump.
    I want the error message for third case also not a shot dump.
    I used 'cO' also but the problem in his is that it not except the only one character like only '1' or '2' it want all the three field should be filled.
    Can  anyone help me out in his problem.
    Thanks
    Chetan.

    hi chetan
    follow this.. it will automatically check your requirement.
    if you want that move to character field... you can..
    <b>data: v_num type NUM03,</b>
          v_char_low type CHAR03,
           v_char_high type CHAR03
    <b>select-options s_number for v_num</b>.
    v_char_low = s_number-low.
    v_char_high = s_number-high.
    Please Close this thread.. when u r problem is solved
    Reward if Helpful
    Regards
    Naresh Reddy K

  • Send to Printer operation and Printer Protocol

    Hello all,
    I designed a process where it is needed to send a PDF file to 2 different printers (not at the same time). So to simplify the process I defined a XML within the server ( C:\config.xml ) with the information necessary to send the job to the printer, and contains the information that the operation sendToPrinter needs:
    - Printer Protocol
    - Server URI
    - Printer Name.
    So instead of placing the values for this operation, I read the values from the XML file. The problem is, the sendToPrinter operation expects the Printer Protocol as a specific type: PrinterProtocol (obvious heheh). And my variable is String.
    How can I convert this?
    Thanks!

    Hi Pal,
    Yeah, we're always replying to ourselves when the problem is a little bit off the main road, aren't we? 
    Are you back to Brazil already?
    Marcos

  • Unsupported Relational Operator Types and DB2e 9.1

    Hello,
    we are using MAM3.0SR3 and adapt this application. So during SP20 installtion we had to swtich to DB2e 9.1 (Prerequisit). However, know it seams the relational operator type LIKE doesn't work anymore. I also tested similar relational operator types which also don't work anymore:
    RelationalOperatorType.LIKE_INSENSITIVE (wildcard "*")
    RelationalOperatorType.LIKE (wildcard "*")
    RelationalOperatorType.SQL_LIKE (wildcard "*")
    RelationalOperatorType.IN
    All the mentioned operator types producing NullPointerExceptions. I used DB2e 8.2.4 before and there LIKE was working fine (the others I didn't test with DB2e 8.x.x). Now I use CONTAINS.
    There exists STARTS_WITH too, but for "ENDS_WITH" is now replacement available (which could realized with LIKE before).
    Know anybody of you a SAP note or document, where these restriction are described? And what about ENDS_WITH?
    Thanks in advance
    Andreas Dommes

    Hi Andreas,
    have a look here - hopefully that helps:
    http://publib.boulder.ibm.com/infocenter/db2e/v9r1f1/index.jsp?topic=/com.ibm.db2e.doc/adg/dbeapr1112.htm
    Furthermore if the DB is not active - have you tried to deploy it manually?
    Regards,
    Oliver
    Message was edited by: Oliver - sorry, first reply was just wrong.
            Oliver Kaluscha
    Message was edited by:
            Oliver Kaluscha

  • Relation between operation and component in Production order

    Hi All
    I am new to PP. I need to get the tables which gives relation between operation and components in Production Order. I need to display in smartform the components assigned.
    Thanks and regards
    Swetabh Shukla

    Hi,
    Try with AFVV Table.
    You need to get the Details of the Filed : AUFPL from AFKO.
    Hope this helps..
    Regards,
    Siva
    Hi,
    You can get the details from Table : RESB.
    Regards,
    Siva
    Edited by: Siva Kumar M on May 23, 2008 10:49 AM

  • Add Even and Odd Numbers

    I have a programming assignment that needs to read a set of integers and then finds and prints the sum of the evens and sum of the odds.
    I know how to find out which numbers are odd and even, I just can't figure out how to add up the evens and odds. Say a set of 10 integers is inputted, how can they be added up after it is determined if they are even or odd?

    Here is my code after the tip from student... It compiles but once ran it doesn't do anything after the integers are put in.
    import java.util.*;
    public class EvenOddIntegers {
        static Scanner console = new Scanner(System.in);
        static final int limit = 10;
        public static void main(String[] args) {
             int number = 0, limit = 0, sumEven = 0, sumOdd = 0;
             int odds = 0;
            int evens = 0;
             System.out.print("Enter ten positive integers: ");
             while (limit <= 10)
                  number = console.nextInt();
             if (number % 2 == 0)
                  sumEven += number;
             else if (number % 2 != 0)
                  sumOdd += number;
             System.out.println("Sum of even numbers is " + sumEven + ".");
             System.out.println("Sum of odd numbers is " + sumOdd + ".");
    }

  • Incrementing every letter in a string that occupies an odd position.

    Hi, for an "encryption" project, i need your help creating a method that will be incrementing by 5 every char in a string that occupies an odd position in that same string.
    For example : 'adam' should return 'aiar'
    -Method can't use arrays.
    -Method can't use regular expressions like 'split' etc..in order words the teacher wants us to use the simplest stuff inside the String class.
    -Only letters must be modified.
    so far i have this : (names of values are in french, sorry)
    public class Main {
    public static String incrementerDeCinqImpaires (String chaine) {
    char j = chaine.charAt(1);
    char x = chaine.charAt(3);
    char o = chaine.charAt(5);
    j+=5;
    x+=5;
    o+=5;
    System.out.println(x);
    System.out.println(j);
    System.out.println(o);
    String   tmpString = chaine.replace( chaine.charAt(1), j );
    String   tmpString2 = tmpString.replace( tmpString.charAt(3), x );
    String   tmpString3 = tmpString2.replace( tmpString2.charAt(5), o );
    System.out.println( "Original = " + chaine );
    System.out.println( "Result   = " + tmpString3 );
    return tmpString3;
    public static void main (String args [] ) {
           System.out.println (incrementerDeCinqImpaires("adam"));
    }The thing is i need a "for" loop (which has been a nightmare for me trying to figure out how to make it) in order to increment every odd positioned char in the string.
    So all I need really is to sum up what i posted above inside a for loop (or more). Then just add ifs and elses so i can increment only letters.

    I don't think String.replace will do what you want. What happens when a single letter appears in an even-numbered position and then in a later odd-numbered position?
    Can you use StringBuilder?
    Or you can do a bunch of String appends (i.e., use StringBuilder implicitly), one character at a time, in a loop.
    By the way you haven't done the part where you check that the character is a letter.
    Also, what do you do with the last five letters of the alphabet? (Regardless of the alphabet you're using.) You could end up inserting control characters or characters that you can't print in your locale. Do you wrap?

  • "One and Done" Printing, Corrupt PDFs

    I'm hoping someone has encountered this odd printing mis-behavior and might be able to offer a solution:
    Upon printing multi-page PDFs to an HP 5640 from Tiger, my Powerbook invariably prints the first page (which, of course, is the LAST page of the document), but as the printer nears the bottom of the page, it pauses, waits for a minute or so (during which time the Deskjet 5600 utility registers the printer as printing subsequent pages), then releases that page, calling it a day. Of course, every remaining page of the document still remains undone!
    I can print the document by initiating a Print command for EACH INDIVIDUAL PAGE, by specifying "Print: From Page 20 to Page 20," "Print: From Page 19 to Page 19," and so on (and have done this for the last few weeks, but this is no way to live!
    On a possibly related note, the PDFs that I am trying to print often corrupt upon trying to save them to a folder, going through the motions of saving but revealing themselves as "empty" PDFs (the drawer shows an equivalent number of blank pages).
    I've tried repairing permissions, to no avail. Might this be a job for Disk Utility or some other repair-oriented program, or might trashing the .plist file for Preview be the best course of action?
    Any help I can find will be greatly appreciated!
    Regards,
    Darren

    I found the answer by myself!
    When I opened a PDF document in "Preview" instead of using Adobe Reader, I was able to print without any problem.
    Apparently there is something in the Adobe print function that is not working correctly. Hopefully it can be fixed sometime; otherwise, I'll just use "Preview" exclusively.

  • Requesting help-On a report Getting ora-00920 invalid relational operator.

    Hi everyone,
    I am having a report region with the following query:
    select CASE
    WHEN ISITRECENTADDENDUM(meckey_fk,code)
    THEN
    '<a href="javascript:popUp2('''
                   || 'f?p=&APP_ID.:61:&SESSION.::NO::P61_MECKEY_FK:'
                   || &P60_MECKEY.
                   || ''', 700, 700);">'
    || '<img src="#IMAGE_PREFIX#gobut.gif">'
    || '</a>'
    ELSE NULL
    END EditAddendum,
    '<a href="javascript:popURL('''
                   ||'&REPORTS_URL.keynewmec&P_1=&P60_MECNUM.'
                   || ''', 700, 700);">'
    || '<img src="#WORKSPACE_IMAGES#printer.jpg">'
    || '</a>'
    PrintMEC,
    "CODE",
    "MECKEY_FK",
    "ADDENDUM",
    "WHO_CREATED",
    "WHEN_CREATED"
    from "C_ADDENDUMS"
    where "MECKEY_FK" = v('P60_MECKEY')
    And my function returning boolean is as follows:
    create or replace FUNCTION "ISITRECENTADDENDUM"
    (meckeyi in number,
    codei in varchar2)
    return Boolean
    is
    x varchar2(1);
    begin
    select max(code) into x from c_addendums where meckey_fk = meckeyi;
    if x = codei then
    return true;
    else
    return false;
    end if;
    exception
    when others then
    return FALSE;
    end;
    But I am getting ORA-00920 invalid relational operator. Can anyone please help me out? I am not knowing where the error is. When I run the function by itself I am getting "False" returned as expected. Appreciate any advice on this.
    Rgds,
    Suma.

    Suma,
    It looks like what you are trying to do is display a link for the record with the highest value in the Code column, and nothing for the other records.
    If that is the case, you can eliminate the function and just use a SQL query like this:
    (not tested)
    select CASE
              WHEN code = Max(code) over (partition by meckey_fk)
                 THEN
                   '<a href="#">'
                   || ' '
                   || '< img class="TargetAlertIcon" src="chrome://targetalert/content/skin/internal.png"></a>'
              ELSE NULL
           END EditAddendum,
           '<a href="#">'
           || ' '
           || '< img class="TargetAlertIcon" src="chrome://targetalert/content/skin/internal.png"></a>' PrintMEC,
           "CODE", "MECKEY_FK", "ADDENDUM", "WHO_CREATED", "WHEN_CREATED"
      from "C_ADDENDUMS"
    where "MECKEY_FK" = :P60_MECKEYIs that what you're trying to do?
    Doug

  • Relational Operator OR

    I am trying to use the OR relational operator in a !Format field and my code only seems to be picking up the first part of the 'or' statement.  Does anyone see anything wrong with this syntax, maybe I have just been looking at it for too long.
    @(If ("@CHECK__PAY_CLS_CD."=="S1021"||"@CHECK__PAY_CLS_CD."=="S1226"||"@CHECK__PAY_CLS_CD."==" S1026", "changed", "@CHECK__PAY_CLS_CD."))
    I would like to see the word "changed" printed if the value is equal to "S1021" or "S1226" or "S1026"  currently it will only print the word "changed" if the first part is true, it doesn't seem to be checking the rest of the expression.
    I'd appreciate any ideas anyone may have.
    Thanks,
    Kris

    I'm using OR operator in my preambe coding and it works well. I'd like to use like this:
    @(If((("@CHECK__PAY_CLS_CD."=="S1021") || ("@CHECK__PAY_CLS_CD."=="S1226") || ("@CHECK__PAY_C LS_CD."=="S1026")), "changed", "@CHECK__PAY_CLS_CD."))
    Hope this can help.

  • When I try open a .pdf file my Adobe Reader 11 only allows the download / save opening the related window and don't show me both options 1) open with ... and 2) save as.... probably someone flagged the choise... always perform this way ....

    When I try open a .pdf file my Adobe Reader 11 only allows the download / save opening the related window and don't show me both options 1) open with ... and 2) save as.... probably someone flagged the choise... always perform this way ....
    Could some one give help and let me know where I can probably find the settings option that allows me to change and switch to previous situation where it was possible to decide time to time how to proceed either opening the file or saving it ??
    Thanks in advance
    David

    What is your operating system?
    Open a PDF from where?  If online, in what browser?

  • My web site has a link which automatically configures an email. Doesn't work in Firefox 5.0 but OK in IE 8, Opera and Netscape. v

    My web site is generated by Second Site , author John Cardinal, and contains email links which when selected automatically createsan email which all you need to do is fill in the body and send it. This has worked in the past in Firefox and does work now using IE 8, Opera, and Netscape browsers but does not work when using my Firefox browser neither locally on my computer or in my Internet website. Firefox is my browser of choice. This has worked in the past using Firefox.
    My web site is www.schulteis.com/omnibus/. On the presentation page, on the bottom, where it identifies Genealogist: Site Administrator. Select it and it may work for you. John Cardinal tested it on his local machine and it worked for him. His response to me was,
    "It's very likely that this is some sort of browser configuration error, and it's probably related to using a web-based email client, In
    Firefox, look under Options > Applications and see how the "Mailto" Content type is configured. It should probably say "Use Yahoo Mail" [it does]. I have never configured a browser to use a web-base email client, so I can't help more than that.
    Since this works fine on my computer and on my Internet site when using browsers IE 8, Opera, and Netscape but not Firefox, and I didn't do anything special for any browser to cause it to work, don't know what I could have done wrong for Firefox.
    I am using Yahoo mail.
    Thanks for your help
    Donald
    [email protected]

    I'm also running FF 36.0.4 on a Win 7 machine.  Here is what I see when I "open" the map (from the server - not inside DW):
    The map area stays white with no image even after several minutes.  The cursor does change to a hand when over the area where the map should be and if I click and drag there the cursor switches to the closed hand - so it's acting like the map is there and can be moved - but just no map shows up.
    I'll run it though the validator.  Thanks!

  • I have set up my airprint wifi printer which works perfectly with the HP eprint app. However, when i view an email and click on the top right arrow button and select "PRINT" on my ipad nothing happens????...

    I have set up my airprint wifi printer which works perfectly with the HP eprint app. However, when i view an email and click on the top right arrow button and select "PRINT" on my ipad nothing happens????...
    Also, when im viewing websites and i find something i wish to print, same again, if i simply click on the print option at the top right of the screen nothing happens... the only way I can print is if i copy the weblink of the site page then click on my HP eprint app and paste the web link, then select print, it prints off fine.. but its it such a pain to keep copying and pasting links or screen dumping emails just to print...

    Just to recap, this is a collection of ports I have collected over time for people who needed this information when setting up the HP ePrint app so that they could view their email from within the app.  I am certain other applications also need this information.  Although lengthy, I could not find a more comprehensive place to retrieve this information.  Feel free to post additional information, faulty information, or other related topics below as this is simply a collection of data and it would be practically impossible to test all of them. Thank you!
    Don't forgot to say thanks by giving "Kudos" if I helped solve your problem.
    When a solution is found please mark the post that solves your issue.
    Every problem has a solution!

  • Network printing: ipp "printer is busy"/LPD and AppSock prints garbled data

    Dear all,
    After months of trying on and off, I give up - I need help please. Since upgrading to Leopard, then Snow Leopard, I cannot print to the office computers. Windows or IPP printer settings produce the "printer is busy - wait 15 seconds" etc error message; LPD and AppSock printer settings enable data to get through, but the output is garbled text (the Adobe Postscript 3 engine on the printer isn't happy, obviously).
    We have some new colour copier/printers from FujiXerox (FX Docucentre IV C3370) and some older Canon laser printers (LBP5600), but they don't offer Bonjour connectivity and I am stuck. I can ping them, I have the latest drivers, but nothing works. They worked fine in OS10.4 on this same computer, and XP and Windows 7 of course in BootCamp, but nothing in OS10.5 or 10.6.
    I've been all over the web and through the Discussions forums and tried all the suggestions I can see, to no avail. I've tried KeyChains to carry by login ID and password to the machines, and deleting/adding printers through both the System Preferences and the CUPS interface, but I confess I am stuck. I currently copy all of my documents every day to a Dell desktop on my desk just to print them out.
    The Canons are run through a Windows server, the FujiXerox has a standalone IP address and no separate print queue at the moment. Running OS10.6.2 on MacBook Pro. I'm happily connected to the network and can access all sharepoints and servers, I just can print to any of the printers - it's infuriating.
    Is it a Firewall problem? Sub-net problems? Any ideas most welcome, thanks for looking and sorry if I've missed out anything important.

    MacJapan wrote:
    After digging around I found the Windows drivers are ART EX drivers; obviously that doesn't really come in Macintosh flavour, but FujiXerox do have a non-postscript driver for the machine which I downloaded. This time I could connect via LPD, as FujiXerox recommend, but the print job stalls at the spooling stage; the error message reads that the 'Library/Printers/FujiXerox/Filter/FXPSACMMFilter.bundle/Contents/MacOS/FXPSACM MFilter' failed.
    The filter bundle crashing could be related to permissions on the filter or a result of using a 32bit driver with a 64bit application.
    For the permissions, you could opening Terminal and entering the following text;
    sudo chown -R root:wheel /Library/Printers/FujiXerox/Filter/
    then press ENTER. You will be prompted to enter you user name and password. The user name needs to be an account that has admin rights to the Mac.
    Exit Terminal and restart the Mac. Now try printing again.
    Regarding the 64bit apps, these are the included SL apps like Preview, TextEdit and Safari. If you attempted to print with one of these apps when you got the error, you could try forcing the app to open in 32bit mode. This is done with the application closed. Locate the app with Finder and do a Get Info on the package (icon). There will be the option to 'Open in 32bit mode'. Select this, close the Get Info window and open the app. Now try a print.
    Regarding the Non-Postscript driver, looking at the FJ drivers web site, there are two of these drivers available. Both are showing as version 1.1, but the dates are different. Have a look at the following link to see if you have the one with the most recent date.
    http://onlinesupport.fujixerox.com/setupDriverForm.do?ctrycode=AU&lang_code=en&dlang=en&pid=DCIVC3370
    Greg's suggestion to use the Generic PCL is also a good alternative. One thing I did find however with the PCL5c is that it does not print in colour, even though it would suggest it does based on the name (the c normally indicates colour).
    Did you get the Canon LBP printing?
    Pahu

Maybe you are looking for

  • I have a short video saved to my PC - how do I get it on to my iPad?

    Have been trying to get the film from my video file on my PC in to itunes to put on my ipad but getting nowhere.  Can anyone give me an 'idiots guide' on how to do this please??

  • Problem with rotate (Win 10)

    For some reason, my Yoga 2 Pro refuses to get back into the 'normal' rotation (NOT upside-down or sideways). I've tried disabling ymg in services (no effect), I've tried with the ctrl-alt combo (all of them work perfectly, EXCEPT for the ctrl-alt-UP

  • Network Error when I run Web Form

    I've got the following message when I run form on web. FRM-99999 : A network error occurred, the client will not be able to continue. Details ... Java Exception : java.net.SocketException : Socket read failed Is there any file missing when I setup my

  • Network management security - Switches and SVIs

    Hello all. I have created a management vlan on my 4506. There are also other SVIs for other VLANs. I understand configuring access-lists for the management vlan as well as for all vty lines limiting to an IT VLAN for example.  How can I remove telnet

  • Simple fcs setup

    I am looking to use fcs on a mac pro with fw drives attached for storage. no network of any kind is involved. Is there a way to catalog the drives without creating duplicate media . I only edit full quality video and have no need for lower res proxie