Results 1 to 2 of 2
  1. #1
    esined93 is offline Member
    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0

    Unhappy What am I doing wrong here??

    I have done this program, everything is working exempt the last if-statement, when i type in 0 as the first number, it continues to write in another number instead of just writing out Thank you.

    import java.util.Scanner;

    public class Uppgiftb {
    public static void main(String[] args) {
    Scanner reader = new Scanner(System.in);

    System.out.println("Write any numberl");
    int a = reader.nextInt();

    System.out.println("Write another number");
    int b = reader.nextInt();

    if (a > b) {
    System.out.println(a + " is bigger than " + b);
    } if (a < b) {
    System.out.println(b + " is bigger than " + a);
    } if (a==b) {
    System.out.println("The numbers are the same");
    } if (a==0) {
    System.out.println("Thank you.");
    }

  2. #2
    Daryn is offline Senior Member
    Join Date
    Oct 2012
    Posts
    176
    Rep Power
    3

    Default Re: What am I doing wrong here??

    It is because you never told it not to do the other thing. What I did(i fixed it on my computer) is use a if else statement were after the first number is typed if it equals to zero do this if not do this

Similar Threads

  1. Replies: 4
    Last Post: 06-11-2013, 02:37 AM
  2. I can't find anything wrong with this but somehow it's wrong.
    By Biscuit Tickler in forum New To Java
    Replies: 2
    Last Post: 09-12-2012, 10:28 PM
  3. Anyone know what is wrong?
    By BChow in forum New To Java
    Replies: 5
    Last Post: 11-02-2011, 12:09 PM
  4. Something is Wrong O.o
    By Spidermonkey in forum Advanced Java
    Replies: 16
    Last Post: 11-14-2010, 05:33 AM
  5. What exactly am I doing wrong?
    By SeanC in forum New To Java
    Replies: 3
    Last Post: 09-27-2010, 04:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •