Something Wrong in the Code

The following code gave me an error: Exception in thread "main" . Anyone, please help me.
import java util.Scanner; // program uses class Scanner
public class Comparision
     // main method begins execution of Java application
     public static void main(String args[])
          // create Scanner to obtain input from command window
          Scanner input = new Scanner(System.in);
          int number1; // first number to compare
          int number2; // second number to compare
          System.out.print ("Enter first integer: ") //prompt
          number1 = input.nextInt(); // read first number from user
          System.out.print("Enter second integer:")//prompt
          number2 = input.nextInt(); // read second number from user
          if(number1==number2)
               System.out.print("%d==%d\n",number1,number2);
          if(number1!=number2)
               System.out.print("%d!=%d\n",number1,number2);
          if(number1<number2)
               System.out.print("%d < %d\n",number1,number2);
          if(number1>number2)
               System.out.print("%d < %d\n",number1,number2);
          if(number1<=number2)
               System.out.print("%d <= %d\n",number1,number2);
               if(number1>=number2)
               System.out.print("%d>=%d\n",number1,number2);
     } // End Method main
} //end class Comparison

As much as I know, it's printf() and not print() method that accepts variable arguments. Also, at least in the code you provided there are two semicolons missing (before //prompt comments). Here's the corrected code:
public class Comparison {
    // main method begins execution of Java application
    public static void main(String args[]) {
// create Scanner to obtain input from command window
        Scanner input = new Scanner(System.in);
        int number1; // first number to compare
        int number2; // second number to compare
        System.out.print("Enter first integer: "); //prompt
        number1 = input.nextInt(); // read first number from user
        System.out.print("Enter second integer:");//prompt
        number2 = input.nextInt(); // read second number from user
        if (number1 == number2)
            System.out.printf("%d==%d\n", number1, number2);
        if (number1 != number2)
            System.out.printf("%d!=%d\n", number1, number2);
        if (number1 < number2)
            System.out.printf("%d < %d\n", number1, number2);
        if (number1 > number2)
            System.out.printf("%d < %d\n", number1, number2);
        if (number1 <= number2)
            System.out.printf("%d <= %d\n", number1, number2);
        if (number1 >= number2)
            System.out.printf("%d>=%d\n", number1, number2);
    } // End Method main
} //end class Comparison

Similar Messages

  • I'm trying to add the system date with a Label. What is wrong with the code

    import java.util.*;
    import javax.swing.*;
    public class CurrentDateApplet extends JApplet
         Calendar currentCalendar = Calendar.getInstance();
         JLabel dateLabel = new JLabel();
         JPanel mainPanel = new JPanel();
         int dayInteger = currentCalendar.get(Calendar.DATE);
         int monthInteger = currentCalendar.get(Calendar.MONTH)+1;
         int yearInteger = currentCalendar.get(Calendar.YEAR);
         public void init()
              mainPanel.add(dateLabel);
              setContentPane(mainPanel);
              dateLabel.append(currentCalendar.get(Calendar.HOUR) + currentCalendar.get
                        (Calendar.MINUTE);
    }

    As for what's wrong with the code, it would be easier if you said: it doesn't show the date (it does this instead), it doesn't compile (I get this message) etc.
    Anyway I'll assume you want to display the time in a label...
    dateLabel.append(currentCalendar.get(Calendar.HOUR) + currentCalendar.get
    (Calendar.MINUTE);This won't compile: the parentheses are mismatched, and there is simply no such thing as append(). So we could trydateLabel.setText("" + currentCalendar.get(Calendar.HOUR) + currentCalendar.get(Calendar.MINUTE));This wroks, but looks pretty nasty and it's not how you are supposed to format dates and times. Here's the unofficial party line, nicked from one of jverd's posts:
    Calculating Java dates: Take the time to learn how to create and use dates
    Formatting a Date Using a Custom Format
    Parsing a Date Using a Custom Format
    From those links you should be able to find those applicable to times like this: http://www.exampledepot.com/egs/java.text/FormatTime.html
    Using this approach you would end up with something like:import java.text.Format;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import javax.swing.JApplet;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    public class CurrentDateApplet extends JApplet
        private Date date;
        private JLabel timeLabel;
        private JPanel mainPanel;
        public void init()
            mainPanel = new JPanel();
            timeLabel = new JLabel();
            mainPanel.add(timeLabel);
            setContentPane(mainPanel);
            date = new Date();
            Format formatter = new SimpleDateFormat("HH:ss a");
            timeLabel.setText(formatter.format(date));
    }

  • I have a Mid 2009 Macbook Pro 13 with no restore disk; it has OS 10.8.4 I believe there is something wrong with the OS due to I can not install flash player to view Youtube videos and the when we plug in a Bose headset the sound out will work sometimes

    I bough a used Macbook Pro mid 2009 that came with OS 10.8.9 it didn't have a backup restore disk with S/N W8******66D
    When trying to view some youtube videos; a window would pop up saying "it needs adobe flash player is required for video play back get the latest flash player" but after downloading the file and during installation would have errors and will not installed.....tried to reboot and install again.....but still the same.
    The othe thing I had noticed is when using a good Bose headset with mic the sound output would noticed the headset and then switch from headset to Internal speekers and headset.....thinking that there might be something wrong with the plug in port of the computer or the headset.....the headset works with no issues on my iPad so there must be something wrong with the computer.....tried to move the plugin around the port but no change....while the headset is plug in can hear a short clicking noise and the sound would get lost and back again......but with nothing plugin to the port there is no issue with the sound or mic.
    Thanks for your feed back......it looks like I have two different issues one is a software issue and the outher is a hardware issue
    <Edited By Host>

    The "restore disk" is built into the Mac. See About Recovery.
    Need more specifics about what error messages you got while installing Adobe Flash.
    However, you can almost avoid Flash altogether by setting YouTube to play the HTML5 version instead.
    Click the Try something new! link at the bottom of the YouTube page.
    I don't know about the sound issue. Might be hardware as you think. Try other headphones to check.

  • There is something wrong with the volumes buttons in my macbook pro, every time i pressed the one who raises the volume, it leads me to the screen where (i do not no what its called) the background is black with the date and time and a calculator.

    There is something wrong with the volumes buttons in my macbook pro, every time i pressed the one who raises the volume, it leads me to the screen where (i do not no what its called) the background is black with the date and time and a calculator. However, when i lower it, my safari tab goes out of the screen. What do you guys think i should do? I'm getting very nervous.

    hey HAbrakian!
    You may want to try using the information in this article to adjust the behavior of your function keys to see if that resolves the behavior:
    Mac OS X: How to change the behavior of function keys
    http://support.apple.com/kb/ht3399
    Take care, and thanks for visiting the Apple Support Communities.
    -Braden

  • I synced. All my music disappeared. Now it will only sync my apps and not my music. Is something wrong with the port on my ipod, the USB cord, or Itunes?On Itunes it says I still have all my music. :(

    I synced my ipod to my computer and all my music disappeared. I tryed resyncing it and it would only sync my apps and not my music. I cant add music to my ipod. I something wrong with the USB port in the IPOD, the USB Cord, or ITUNES itself. Itunes still shows that all my music is there on my ipod. Itunes is recognizing that my ipod is connected, but it doesnt recognize that theres no music on my ipod anymore. Im so sad. Someone please help me. I miss my music.

    The music sync is one way - computer to ipod.  The only exception is itunes purchases.
    The ipod is not a storage/backup device.  It simply mirrors the selected content of your computer.
    As the music came from your computer in the first place, it should still be there and in your backup copy of your computer.

  • "The file 'Acknowledgements.rtf' cannot be installed because the file cannot be found in the cabinet file 'iTunes.cab'.  Is there something wrong with the latest installer? (11.3.1)

    Getting error message as shown: "The file 'Acknowledgements.rtf' cannot be installed because the file cannot be found in the cabinet file 'iTunes.cab'.  Is there something wrong with the latest installer? (11.3.1)

    Installs fine for me, so I'd guess you got an incomplete or corrupt download. See the Further Information area of Troubleshooting issues with iTunes for Windows updates for direct links and download a fresh copy of the installer.
    tt2

  • What's wrong with the code?

    public void run()
    try
    {     for(;;)
         mgr = (RTPManager)RTPManager.newInstance();
         mgr.addSessionListener(this);
         mgr.addReceiveStreamListener(this);
         try{  /*****port1 = port2 = 29261, which port is only used in here
         localAddr = new SessionAddress(InetAddress.getLocalHost(), port1);
         destAddr = new SessionAddress(ipAddr, port2);
         }catch(Exception e)
              System.out.println(e + " 4");
         try{
         mgr.initialize(localAddr);
         }catch(Exception e)
         System.out.println(e + " 5");
         //set buffer
         bc = (BufferControl)mgr.getControl("javax.media.control.BufferControl");
         if (bc != null)
         bc.setBufferLength(20);
         try{
              mgr.addTarget(destAddr);
         }catch(Exception e)
         System.out.println(e + " 2");
    catch(Exception e)
         System.out.println(e+ " 3");
    the error when i run the code is like that:
    javax.media.rtp.InvalidSessionAddressException: Can't open local data port: 29261
    5
    java.io.IOException: Address already in use: Cannot bind 2
    which means there is error in :
    mgr.initialize(localAddr);
    mgr.addTarget(destAddr);
    But i don't know what's wrong with the code,
    can any one help me?

    I do not find any problem using the same ports for local and destination address with several unicasts. My problems are others.
    But note that the error is even at constructing the localAddress, I mean before trying the destinationAddress. Thus the reason cannot be the former is already in use. In fact I think the later belongs to a remote hosts. Likely, it is trying to access the destinationAddress through the localAddress, but this has not been constructed properly.

  • Is there something wrong with the IOS 6 update?

    Ever since I downloaded the iTunes IOS 6 update on my 2nd-gen iPad, I haven't been able to check my list of purchased apps in the purchased section the iTunes store app. I tried logging out & signing back in and I tried rebooting my iPad, but neither of them worked. Can you please fix the IOS update? Thanks if you and keep up the incredible work!

    Never mind, there's definitely something wrong with the IOS 6 update. Sometimes the App Store doesn't show that an app has been purchased & it only shows the price of the app. Other times, it doesn't show that an app is currently being downloaded or that it's installed.
    Still though, Apple, you really do need to fix this IOS 6 because the Purchased Apps section won't finish loading & display the ones that have been purchased. Also, you need to improve the App & iTunes gift card payment method because if you use a credit card & then switch back to gift card, it doesn't remember how much leftover money you had before & you can't combine the change from the previously-used ones together into one lump of money.
    32 cents isn't enough to buy anything, not even a $0.99 app. The money is going by without being used and its a waste of money! If it's possible, please fix these two problems. Thanks if you do & keep up the incredible work!!!!!

  • Red highlight next to code in dreamweaver. What is wrong with the code and is it affecting the websi

    What is wrong with the code and is it affecting the website?

    Line 107 looks dodgy to me and it won't have any effect on your code.  However, it is a good idea to post a complete link to your CSS for us to see it in full and to validate it using external tools.  In fact, you could validate the CSS (and HTML) yourself..
    <http://jigsaw.w3.org/css-validator/>
    Good luck.

  • There is something wrong with the forum

    There is something wrong with the forum. it is messed up.!
    I been a little bit observant this past few days, I observed alot of problems..
    here are a few, ( there are actually alot more, but I could not describe it. its just very weird.
    I thought someone hacked to my profile and used it to ask that one, but when I clicked on it, it was just one of the questions I have responded to.
    sometimes I can not post to threads, an error would come up, most especially if I reply to a reply,
    sometimes, when I Post images it would work the first time I post it, but when I search for it again, only the links are given, no images anymore.
    sometimes I get booted out randomly, in the middle of writing a reply
    sometimes the posts switches from threaded to flat , flat to threaded, and sometimes both.
    sometimes when I checked on the stuffs>discussion, the post is highlighted but there is no new response or like, and even there was, I can see which one is it, especially to the posts that had many reply already
    sometimes it still sends email to my gmail eventhough i have unsubscribe to the post already,
    sometimes get error 504, and some other numbers I forgot.
    sometimes during writing a response the blinking thing that indicates where are you writing goes missing or on the wrong place.
    OH come on..! I am trying to help, you don't want one?
    and don't blame it on ,my browser ( i checked and used IE9, FIREFOX, and even CHROME), or to my internet connection.( i got the best there is for home connections), or to my laptop ( it's a little bit old, but it still kicks butt holes) and tried it already with other pc/internet connection/and whatnot.
    I am still sometimes visiting my previous home (NOKIA FORUM) and I don't experience those, and we even have live chat over there,
    this forum needs a revamp. and how I wish this could be repaired via Sony Update Service, or PC Companion, but of course if it was possible I would have done it already.
    We try to help users, make the forum conducive for users trying to help users. \m/
    best of luck,,
    MARLON LB :smileywink:

    This is how the forum looks for me.
    But during around midnight, (gmt +8) the forum changes to this

  • My iPhone 4 with cash card is slowly emptying the balance of the card. Only Wi-Fi is normally ON, most other things OFF. Are the Apps responsible for this, or is something wrong with the phone itself? How can I stop the "thief"?

    My iPhone 4 with cash card is slowly emptying the balance of the card. Only Wi-Fi is normally ON, most other things OFF. Are the Apps responsible for this, or is something wrong with the phone itself?  How can I stop the "thief"?

    I have this exact same problem. One solution is having your friends change their fake aliases on Facebook to their real bloody names, but I realise this is no easy fix.

  • Is something wrong with the new software update. My battery dies within 4 hours. There are also problems with my e-mail accounts. Can someone help me?

    Is something wrong with the new software update. My battery dies within 4 hours. There are also problems with my e-mail accounts. Can someone help me?

    Have you attempted an iTunes restore and setting up as a new device? Sometimes battery life issues can be caused by corrupted iOS software.
    - Greg

  • Imac g5-something wrong in the power cord?

    something wrong in the power cord- I can't put it in the computer 100%- it's not sitting there right. I just bought the computer. should I do it in force?

    Don't force it!
    I had same problem for a second, but then it slid in very easily once I relaxed and stopped panicing.

  • My iPad mini keeps freezing up is there something wrong with the iPad do I need to get it fix?

    MMy iPad mini keeps freezing up on me. Is there something wrong with the iPad? It freez a lot when I'm playing the big fish casino game. What can be done to fix this?

    Hello there Lsu70,
    If your app is rendering the iPad unresponsive, I would recommend you use the troubleshooting in this article to help get that resolved, named:
    iOS: An app you installed unexpectedly quits, stops responding, or won’t open
    Start with these steps, but there are additional things to do if these do not resolve the issue:
    Follow the steps below and test the app after each step.Restart the app
    Close the app and open it again.Restart your device
    Turn the device off and on.Update your device software and your apps
    Update your device to the latest version of iOS.
    Update your apps:
    Open the App Store and tap Updates.
    If updates are available, tap Update All.
    If asked, enter your Apple ID password. The updates will download and install.
    You might need a Wi-Fi connection to update some apps.
    Thank you for using Apple Support Communities.
    All the very best,
    Sterling

  • My wifi suddenly wont work on my i4s. i already reset network, forget network, restart, and put it in the refrigerator (coz some people said maybe theres something wrong with the heat of wifi inside ). what should i do?

    my wifi suddenly wont work on my i4s. i already reset network, forget network, restart, and put it in the refrigerator (coz some people said maybe theres something wrong with the heat of wifi inside ). what should i do?
    but sometimes, it can read,but wont connect.
    sometimes it even wont read  the wifi .
    sometimes, when it can connect, the password already correct, but it didnt want to connect.
    it suddenly happened, without i changed the seeetinggs or else.
    i read every solutiuon on google., etc2, and tried the way, but it still wont work.
    anyone can help ? pleasee ;(

    This is a totally absurd suggestion, except that it worked for me with my iPad.  Forget the network, then when asked for the password, enter a wrong one.  Try again and enter the correct password.  Good luck.

Maybe you are looking for

  • Will not search for a word in pdf file. Using Windows 7

    Like most I have used Acrobat reader for viewing PDF files for years.  I recently upgraded to Windows 7 from XP.  I have tried to search a PDF file for a word and it always comes up with none found even though I search for a word that is displayed in

  • Install SOA Suite

    Hi when i install Soa Suite in configuration bpel proceess manager (Item 3) this error show: 08/10/22 00:54:05 Notification ==>Application Deployer for hw_services COMPLETES. Operation time: 3984 msecs Caught exception running the command via the scr

  • V8 SP4 SPNEGO Identity Asserter problem

    I configured my domain to authenticate against AD using the SPNEGO Identity Asserter. Two questions. 1) How do I do authorization ? Do I enter the name of an AD group in the webapps weblogic.xml under Principal-Name? Or use weblogic groups (if so, ho

  • Find all beans referenced on a JSF page for PhaseListener

    I am trying to implement a PhaseListener to do some application specific stuff just before the render response phase. I am trying to find all of the managed beans referenced in the currently executing JSF page. So for example, if I had this in a page

  • Fragmented sound when using Java Synthetizator

    Hi, What is the reason for sound fragmentation when using Java synthetizator in playing midi files: ByteArrayInputStream mididata = new ByteArrayInputStream(data); AudioStream as = new AudioStream(mididata); //pre fragment? Priority problem? mididata