Making a program to detect a palindrome

For my class I have to make a program that will detect whether or not a word is a palindrome. Here's what I have right now:
import java.io.*;*
*import java.util.*;
public class Tester
        public static void main(String args[])
                 Scanner f = new Scanner(System.in);
                 System.out.print("Enter a word. ");
                 String word = f.nextLine();
                 char reverse=0, pali=0;                
                 int j, r;
                 for(j = word.length()-1; j>=0; j--)
                    reverse = word.charAt(j);      //To print the string backwards
                    for(r = 0; r <= word.length()-1; r++)
                        pali = word.charAt(r);     //Printing the string normally                     
                        if(pali!=reverse) 
                            System.out.println(word + " is not a palindrome.");
                            break;
                        else if(pali == reverse)
                        System.out.println(word + " is a palindrome.");                       
}So basically what I'm trying to do there is to have one loop print each character backwards and a loop inside of that print each character forwards, and inside of the second loop I check to see whether the characters are identical, and if they are not, the word isn't a palindrome. It makes sense to me, but the output looks like this, using racecar as an example:
Enter a word. racecar
racecar is a palindrome.
racecar is not a palindrome.
racecar is not a palindrome.
racecar is not a palindrome.
racecar is not a palindrome.
racecar is not a palindrome.
racecar is not a palindrome.
racecar is a palindrome.
racecar is not a palindrome.I understand why it prints that many times, because it's still iterating inside the first loop, but I have no idea how break the first loop. Also, clearly, it just doesn't work... any tips?
All help is greatly appreciated.

Thanks for the reply.
I'm not sure if I got exactly what you meant, but here's how I understood it:
import java.io.*;
import java.util.*;
public class Palindrome
        public static void main(String args[])
                 Scanner f = new Scanner(System.in);
                 System.out.print("Enter a word. ");
                 String word = f.nextLine();
                 boolean b = true;
                 char pali = 0, reverse = 0;
                 int j, r;
                 j = word.length()-1;
                 r = 0;
                 while(j!=r)
                        pali = word.charAt(r);
                        reverse = word.charAt(j);
                        if(pali!=reverse)
                                    b = false;
                                    break;
                        else
                                b = true;
                                r++;
                                j--;
             if(b)
             System.out.println(word + " is a palindrome.");
             else
             System.out.println(word + " is not a palindrome.");
    }I made a mistake somewhere, because when I input a palindrome it might say that it is a palindrome(more than once for some reason), but if I input a non-palindrome it doesn't respond at all. No idea why, because I have an "else" statement that should make it do so...
So where did I go wrong?

Similar Messages

  • In Mac OS X, I installed a third party toolbar to Safari which is making the program unusable. How can I uninstall it? It did not have an uninstall option.

    In Mac OS X, I installed a third party toolbar to Safari which is making the program unusable by constantly giving a dropdown box requesting a sign-in to a mail feed. It came from http://WWW.BBshare.com/Products/gtoolbar-for safari
    How can I uninstall the toolbar? It did not come with an uninstall option.

    Instructions for manually uninstaling third party add ons >  Unsupported third-party add-ons may cause Safari to unexpectedly quit or have performance issues

  • OSystem Program Problem Detected Window, asks if I want to report this, then it asks for my Password ? is this ok ?

    I'm new to Ubuntu & Linuz OS. I've started to see a pop-up window that says: System Program Problem Detected- Do you want to report the problem. When I click yes, I'm asked to enter my password to access problem reports of system programs. Should I be asked for my password ???

    I am fairly new to Ubuntu, but that does not sound unexpected. Ubuntu tends to have everyone use a limited account that needs to ask for a password before carrying out operations like installing software.

  • What is the  best money making java program?

    what is the best money making java program?
    any of them are in fact very "simple"? - say in fact can be develop by a middle- level programmer.

    public class MoneyMaker {
       public static void main(String[] args) {
          while (true) {
             System.out.println("+-----------------------------------------------+");
             System.out.println("| 10        RESERVE BANK OF INDIA \"93T 872468\"  |");
             System.out.println("|                                               |");
             System.out.println("|   ______                                   10 |");
             System.out.println("|  /      \\             __          ____        |");
             System.out.println("|  |      |        /|  /  \\        /  __\\       |");
             System.out.println("|  |      |         | |    |       0_o  \\\\      |");
             System.out.println("|  |      |         | |    |      /      ||     |");
             System.out.println("|  |      |         |  \\  /       `==    ||     |");
             System.out.println("|  |      |        ===  **         \\    /       |");
             System.out.println("|  |      |                        /\\--/        |");
             System.out.println("|  \\______/                       /______   /\\  |");
             System.out.println("|                                           \\/  |");
             System.out.println("| \"93T 872468\"                                  |");
             System.out.println("+-----------------------------------------------+");
             System.out.println("");
    }

  • [SOLVED] Making a program appearing on all workspaces

    Hi!
    Is it possible to making a program appearing on all available workspaces with Fluxbox?
    Last edited by svanberg (2009-08-06 10:46:17)

    I found the solution here.
    Last edited by svanberg (2009-08-06 10:46:03)

  • Having problem making my program play the sound i want it to play...

    Ok, im new at this so bare with me (and my spelling)...
    i've been trying to make my program play a musicfile during the actual program... and trust me, i've tried so many times...
    after the last try i get the errormessage "cannot find symbol" for 2 things...
    import javax.swing.*;
    import javax.sound.sampled.*;
    import java.io.*;
         public class iwish {
              public static void main (String args[]) {
                   AudioClip sound = JApplet.newAudioClip(new URL("file://C:\\Program\\Java\\jdk1.6.0_02\\bin\\iwish1.wav"));
                   sound.play( );
                   String a = JOptionPane.showInputDialog("Vem kan du vara?");
                   String b = JOptionPane.showInputDialog("Jaha " + a + ", sommar eller vinter d??");
                   String c = JOptionPane.showInputDialog("Vem vill du helst av allt ha bredvid dig nu?");
                   String d = JOptionPane.showInputDialog("D? f?rst?r jag, glass eller choklad (du f?r bara v?lja ett f?rslag)?");
                   String e = JOptionPane.showInputDialog("Vart f?redrar du att sova d? (gl?m inte prepositionen)?");
                   String f = JOptionPane.showInputDialog("Ok, om du korsar fingrarna, l?gger du pekfingret under eller ovanp? l?ngfingret?");
                   JOptionPane.showMessageDialog(null, "Ok, jag kommer fram till tv? alternativ:");
                   JOptionPane.showMessageDialog(null, "Alt 1; " + a + ", p? din " + b + "semester har du helst sex \n med " + c + " " + e + " samtidigt som du ligger " + f + " " + c + " som \n f?rsiktigt slickar " + d + " fr?n din kropp, tills hela din kropp skakar av njutning!");
                   JOptionPane.showMessageDialog(null, "Alt 2; Du f?redrar ingen speciell ?rstid eller speciellt st?lle \n att ha sex p?, s? l?nge du f?r ha det med " + c + ". Sedan f?r du \n somna i " + c + "s famn. Glass och choklad kan du alltid f? n?r du vill!");
                   System.exit(0);
    the problem is: iwish.java:10: cannot find symbol
    symbol : class URL
    location: class iwish (at the U) ^
    AudioClip sound = JApplet.newAudioClip(new URL("file://C:\\Program\\Java\\jdk1.6.0_02\\bin\\iwish1.wav"));
    ^
    am I making any sense?! =) what have i done wrong?

    ok, thank you,
    i tried it with the catchphrase and the program worked just as it did when I threw the exception...
    import javax.swing.*;
    import javax.sound.sampled.*;
    import java.io.*;
    import java.net.*;
    import java.net.URL.*;
    import java.applet.*;
    import java.applet.AudioClip.*;
         public class iwish {
              public static void main (String args[]) {
                   try
                   AudioClip sound = Applet.newAudioClip(new URL("file://C:\\Program\\Java\\jdk1.6.0_02\\bin\\iwish3.wav"));
                   sound.play();
                   catch (MalformedURLException j)
                   j.printStackTrace();
    I changed the "e" to a "j" in the "catch (MalformedURLException j)" since I was using the e in one of my strings...
    Was it supposed to work or did I do wrong? =/

  • Please give me a program to display a palindrome.

    PROGRAM FOR PALINDROME AND IF WE GIVE N = 3 O/P SHOULD BE LIKE :
    Edited by: Vijay  Kumar on Jul 15, 2008 2:44 PM

    PARAMETER P_STRING(15) TYPE C.
    DATA:W_A(1) TYPE C,
         W_A1(1) TYPE C,
         W_B TYPE I,
         W_C TYPE I VALUE 1,
         W_D TYPE I,
         W_X TYPE I,
         W_F TYPE I VALUE 0,
         W_E TYPE I VALUE 1.
    W_B = STRLEN( P_STRING ).
    W_D = W_B - 1.
         DO W_B TIMES.
         MOVE P_STRING+W_D(W_C) TO W_A.
         MOVE P_STRING+W_F(W_E) TO W_A1.
         IF W_A = W_A1.
         ADD 1 TO W_X.
         ENDIF.
         W_D = W_D - 1.
         W_F = W_F + 1.
         ENDDO.
         IF W_X = W_B.
         WRITE TEXT-111.
         ELSE.
         WRITE TEXT-100.
         ENDIF.

  • Is there a recommended program to detect hidden Keylogger on OSX?

    I am wondering if anyone knows of a program that is effective in finding any keylogger program that is buried somewhere on my system. I have a suspicion that someone has installed such a program on my mac. If there are any good detection apps out there, I'd appreciate it. Also, is it fairly easy to install a keylogger on OSX? Just wondering, because I know how easy it is on windows. Thanks guys/gals.

    Sorry I'm not able to be more specific regarding a Keylogger but you could try this:
    Launch your activity monitor (Applications - Utilities - Activity Monitor) and look for the keylogger in the active processes. From here you should be able to quit it and identify it for removal (use finder's find to locate and trash the offending article).
    I would assume that it's also a startup item, so have a look in System Preferences - Accounts - Start Up Items and if it's there remove the errant item from the list.
    For someone to have installed a keylogger on your machine, I would suggest that the wrong kind of people have access to your mac or that you have MUCH Greater security concerns which will need addressing.
    Hope this helps.

  • Does anybody have any experience with keyloggers and a good program to detect one on your mac? I think I may have one.

    So yesterday I found out that my email address password had been changed. I don't remember doing this, but it is possible I changed it a while back and considering I keep my email constantly logged in. But at the same time, two of my apps were trying to access their "store". I play a game called League of Legends, which has an online store, and it randomly came up with the message "Could not connect to Maestro" (credit card). Then, Itunes (which I rarely use) came up with "sorry, we could not continue with your purchase". I think it's very strange that all of this happened at the same time, but hopefully it's a case of a forgotten password and two games bugging/crashing. I scanned my entire computer with iantivirus and it hasn't found anything, but I've heard keyloggers can be a bit hard to detect. Does anybody have any experience with keyloggers and if so, what program did you use to detect and destroy it?

    If you think that a keylogger has been installed the only safe thing you can do is erase your drive and reinstall.
    I don't think that is the case however.

  • PLEASE HELP making a program that uses sudo commands

    hey
    is there anyway to make a program run sudo commands
    i have a problem because in a terminal it would ask you to input a password.
    is there a way to use a fake keyboard program to input the password in the back ground
    of my java application or some how run sudo commands? my application relies on some outputs of these commands.
    please help thanks.

    ill tell you a bit about my program im making.
    i have a wireless usb that i have to switch back and forth to get my paticullar drivers to
    do certain things e.g. one is for web browsing and the other one has packet injection.
    by typing sudo modprobe ect.. i can switch through a terminal. which requires me to type in a password.
    iv made a application which uses the
    Runtime.getRuntime().exec("sudo ...."); it has 2 buttons to switch from diffrent drivers and always runs at start up.
    just a big problem i cant use sudo it just freezes when i start and click on the buttons. and doesnt ask me for a password.
    can anyone help thanks

  • Firefox crashes every time I launch it making the program unopenable

    At first firefox 4 was fine for about a couple of months then I notcied it crashing all the time, about 30% of the time I open a new tab or page it would crash.
    Now when I opend firefox I get a crash report before the browser has even opened, even if I open a link in outlook it crashes right away. Perhaps it is openeing a page I had open that it just constantly crashes on or maybe the program crashes upon any open page, I am not sure.
    Give me back firefox 3.0 :( (I was forced to post this using IE it is a sad day)
    <pre><nowiki>
    Windows 7 Ultimate 64 bit
    AMD Phenom II X4 3.4 ghz
    G.skill 8GB RAM 1300mhz
    Gigavyte HD6870
    Running applications:
    Norton: antivirus disabled, firewall allowing all connections from firefox.
    Had no problems before version 4.0
    Error details:
    AdapterDeviceID: 6738
    AdapterVendorID: 1002
    Add-ons: {BBDA0591-3099-440a-AA10-41764D9DB4DB}:2.0,{2D3F3651-74B9-4795-BDEC-6DA2F431CB62}:5.6,{01A8CA0A-4C96-465b-A49B-65C46FAD54F9}:6.0,{53A03D43-5363-4669-8190-99061B2DEBA5}:1.4.5,{73a6fe31-595d-460b-a920-fcc0f8843232}:2.1.1,{972ce4c6-7e08-4474-a285-3208198ce6fd}:4.0.1
    AvailableVirtualMemory: 3995193344
    BuildID: 20110413222027
    CrashTime: 1307144794
    EMCheckCompatibility: true
    FramePoisonBase: 00000000f0de0000
    FramePoisonSize: 65536
    InstallTime: 1305189722
    Notes: AdapterVendorID: 1002, AdapterDeviceID: 6738, AdapterDriverVersion: 8.850.0.0
    D2D? D2D+
    DWrite? DWrite+
    D3D10 Layers? D3D10 Layers+
    ProductName: Firefox
    ReleaseChannel: release
    SecondsSinceLastCrash: 405
    StartupTime: 1307144794
    SystemMemoryUsePercentage: 18
    Theme: classic/1.0
    Throttleable: 1
    TotalVirtualMemory: 4294836224
    URL: jar:file:///C:/Program%20Files%20(x86)/Mozilla%20Firefox/omni.jar!/chrome/browser/content/browser/aboutHome.xhtml
    Vendor: Mozilla
    Version: 4.0.1
    Winsock_LSP: MSAFD Tcpip [TCP/IP] : 2 : 1 : %SystemRoot%\system32\mswsock.dll
    MSAFD Tcpip [UDP/IP] : 2 : 2 :
    MSAFD Tcpip [RAW/IP] : 2 : 3 : %SystemRoot%\system32\mswsock.dll
    MSAFD Tcpip [TCP/IPv6] : 2 : 1 :
    MSAFD Tcpip [UDP/IPv6] : 2 : 2 : %SystemRoot%\system32\mswsock.dll
    MSAFD Tcpip [RAW/IPv6] : 2 : 3 :
    RSVP TCPv6 Service Provider : 2 : 1 : %SystemRoot%\system32\mswsock.dll
    RSVP TCP Service Provider : 2 : 1 :
    RSVP UDPv6 Service Provider : 2 : 2 : %SystemRoot%\system32\mswsock.dll
    RSVP UDP Service Provider : 2 : 2 :
    This report also contains technical information about the state of the application when it crashed.</nowiki></pre>

    See:
    *https://support.mozilla.com/kb/Firefox+crashes+when+you+open+it
    What you posted is not a crash report, but only some information about your setup.
    If you have submitted Breakpad crash reports then post the IDs of one or more Breakpad crash reports (bp-xxxxxxxx-xxxxxxxxx-xxxx-xxxxxxxxxxxx).<br />
    You can find the IDs of the submitted crash reports on the <i>about:crashes</i> page.<br />
    You can open the <b>about:crashes</b> page via the location bar, like you open a website.<br />
    See:
    * http://kb.mozillazine.org/Breakpad (Mozilla Crash Reporter)

  • Cant get into Itunes program itunes detects probl. with audio configuration

    I tried a few times Removing Itunes from my computer and downloading it again and I tried RESTORE to reset
    everything -it DIDN't work keep getting the same message.
    I called the computer company they said I should try calling ITUNES. It's been working o.k. for 6 mos.
    There Doesn't seem to be a problem with the Ipod itself.
    Anyone help me please? Thx.
    The Message I get is:
    Itunes cannot run because it has detected a problem
    with your audio configuration.

    You probably can find an answer to this in the iTunes
    Forum rather than here.
    Yes. Thx. I did get help there.
    emachines mprii   Windows XP  

  • I Need Help With Making This Program Work

    The directions for this program:
    Enhance the Student class to contain an Advisor. The advisor has a name (type Name), phone number (type String). Place edits in the Name class to validate that the length of the first name is between 1 and 15, middle inital <= 1, and lastName is between 1 and 15. Throw an IllegalArgumentException if the edits are not met. The advisor attribute in the Student class should replace the advisorName. Document the Name, Advisor, and Student classes including the preconditions and postconditions where necessary. Create a test class that will instantiate a Student, fully populate all of its fields and print it out. Do not document the test class. Submit for grade Student.java, Advisor.java, and Name.java.
    public class Student
         private Advisor advisorName;
         private Advisor phoneNumber;
         public void setAdvisorName(Advisor anAdvisorName)
             advisorName = anAdvisorName;
         public Advisor getAdvisorName()
             return advisorName;
         public void setPhoneNumber(Advisor aPhoneNumber)
             phoneNumber = aPhoneNumber;
         public Advisor getPhoneNumber()
             return phoneNumber;
    public class Name
         private String firstName;
         private String midInit;
         private String lastName;
         public String getFullName()
             return firstName + " " + midInit + " " + lastName;
         public String getFirstName()
             return firstName;
         public String getMidInit()
             return midInit;
         public String getLastName()
             return lastName;
            Calculates length of the first name.
            (Postcondition: getFirstName() >= 0)
            @param s the length of the first name to calculate
            (Precondition: length of aFirstName > 0 and <= 15)
         public void setFirstName(String aFirstName)
             if(aFirstName.length() < 1)
               throw new IllegalArgumentException();
             if(aFirstName.length() > 15)
               throw new IllegalArgumentException();
               firstName = aFirstName;
            Calculates length of the middle initial.
            (Postcondition: getMidInit() >= 0)
            @param s the length of the middle initial to calculate
            (Precondition: length of s > 0 and <= 1)
         public void setMidInit(String aMidInit)
             if(aMidInit.length() == 1)
               throw new IllegalArgumentException();
               midInit = aMidInit;
            Calculates length of the last name.
            (Postcondition: getLastName() >= 0)
            @param s the length of the last name to calculate
            (Precondition: length of aLastName > 0 and <= 15)
         public void setLastName(String aLastName)
             if(aLastName.length() < 1)
               throw new IllegalArgumentException();
             if(aLastName.length() > 15)
               throw new IllegalArgumentException();    
               lastName = aLastName;
    public class Advisor
         private Name advisorName;
         private String phoneNumber;
         public String getFullName()
            return advisorName + " " + phoneNumber + " ";
         public Name getAdvisorName()
             return advisorName;
         public String getPhoneNumber()
             return phoneNumber;
         public void setAdvisorName(Name anAdvisorName)
             advisorName = anAdvisorName;
         public void setPhoneNumber(String aPhoneNumber)
             phoneNumber = aPhoneNumber;
    public class Test
         public static void main(String[] args)
            Name name1 = new Name();
            name1.setFirstName("Timothy");
            name1.setLastName("O'Neal");
            name1.setMidInit("J.");
            System.out.println("name1 = " +
                name1.getFirstName() + " " +
                name1.getMidInit() + " " +
                name1.getLastName());
            Student st = new Student();
            st.setAdvisorName(name1);
            Name name2 = st.getAdvisorName();
            System.out.println("name2 = " +
                name2.getFirstName() + " " +
                name2.getMidInit() + " " +
                name2.getLastName());   
            name2.setFirstName("Timothy");
            System.out.println("name2 = " +
                name2.getFirstName() + " " +
                name2.getMidInit() + " " +
                name2.getLastName());       
            System.out.println("name1 = " +
                name1.getFirstName() + " " +
                name1.getMidInit() + " " +
                name1.getLastName());
            System.out.println("name1 = " + name1.getFullName());   
            System.out.println("name2 = " + name2.getFullName());
    }I can't get the test class to compile and i'm not sure if this is what i'm suppose to do

    public class Test
    public static void main(String[] args)
    Student st = new Student();
    Advisor advisor = new Advisor();
    st.setAdvisor(advisor);
    Name name1 = new Name();
    name1.setFirstName("Jake");
    name1.setLastName("Schmidt");
    name1.setMidInit("K.");You have the general idea, I think. You are just doing it backwards.
    You create and advisor and assign it to a student. But you don't give
    the advisor a name until after you assign it to the student.
    You should create an advisor, give the advisor a name and then add it to the student.
    //create the name
    Name name1 = new Name();
    name1.setFirstName("John");
    name1.setLastName("Smith");
    name1.setMidInit("K.");
    //create the advisor
    Advisor advisor = new Advisor();
    advisor.setAdvisorName(name1);
    //create the student
    Student student = new Student();
    //assign the advisor to the student
    student.setAdvisor(advisor);
    //now the student has an advisor named John K. Smith
    //What is the name of the advisor?
    String name = st.advisor.getAdvisorName().getFullName();
    //I know that line looks complicated...but that's how you have created your class structure.
    Instead you could have done:
    Class Student{
    private Advisor advisor;
    public String getAdvisorName(){
    return advisor.getFullName();
    class Advisor{
    private Name advisorName;
    public getFullName(){
    return advisorName.getFullName();
    This way, if you wanted to know the advisor's name you would go:
    String name = st.getAdvisorName();
    which is much easier.
    I think it would be much easier to help you if we were both in the same room, on the same computer :)

  • Making the program react to input from keyboard

    Hello,-
    I am trying to write a program that reacts to user input: when one hits the "y" key on keyboard the program should print out a statement or perform some other action. The following piece of code compiles, but ignores the if-part. Does anyone have any tips?
    Thanks, Vahagn
    import java.io.*;
    public class InputPrinter {
        public static void main(String[] arg) throws IOException {
         InputStreamReader isr = new InputStreamReader(System.in);
         BufferedReader br = new BufferedReader(isr);
         String line = br.readLine();
         //works perfectly
         //doesn't work:
         if (line == "y")
             System.out.println("Hello World!");
    }

    Thanks, that was exactly what I needed:
    import java.io.*;
    public class InputPrinter {
        public static void main(String[] arg) throws IOException {
         InputStreamReader isr = new InputStreamReader(System.in);
         BufferedReader br = new BufferedReader(isr);
         String line = br.readLine();
         //works perfectly
         //doesn't work: if (line == "y")
         if (line.equals("y"))
             System.out.println("Hello World!");
         else
             System.out.println(4+4);
    }In the long run I AM interested in a program that processes input as it happens, without printing the input itself and without hitting the ENTER key. It was nice though to have sorted the above problem out.
    Regards to all, Vahagn

  • I need help in making the programe which updates our code into client machi

    I need help in making the programme which updates our code into client machine from the server.
    As yahoo messanger does if there is any updated version of yahoo messanger.
    It asks when we login into it do you want to update new version of yahoo messanger
    It automatically updates it
    Need Help??

    Sounds to me like you need Java Web Start.

Maybe you are looking for

  • JNI and loadlibrary

    I know there are about a billion topics already posted on this subject but I am getting nowhere with this issue. I was able to get java to see the path and the shared library file that I want to load using java -Djava.library.path=. myjavaclass. Howe

  • Performance issues in modeling process chains

    Hi friends ,   what are the steps to be taken care in modeling a process chains.. Iam talking with respect to loading performance ... The design of process chian should not hinder the loading process--  plz help. my id is [email protected]   Regards,

  • Purchased album, 1 song wont play

    purchased kanye and jay-z new album, all songs appear but 1 song illest motherf***** alive wont play

  • Exception in thread "main" java.lang.NoClassDefFoundError: Files\Apache

    Hi, I am new to smart card.I have installed and configured the JCDK.When i try to run the build_sample.bat,I got the following error. Exception in thread "main" java.lang.NoClassDefFoundError: Files\Apache can you guys give me the solution please.Tha

  • Individual batch number generation.

    hello gurus, My client brings in rolls of material which is batch managed. He wants independent batched generated for the rolls. eg. if a truck load contains 300 rolls, the clients wants 300 batch number generated at the time of posting of gr. but wh