Results 1 to 2 of 2
  1. #1
    gquach is offline Member
    Join Date
    Aug 2013
    Posts
    2
    Rep Power
    0

    Default Largest and smallest numbers program

    i also have the same problem. Art_88, your code works, but my code doesn't work in the same way. Can you please help me and answer me why doesn't my code work as it is when entering -99 to end and show the results.
    here's my code:

    import java.util.Scanner;


    public class number_17737816 {

    public static void main(String[] args) {

    Scanner keyboard = new Scanner(System.in); //get Scanner class for keyboard input
    int values; //values for integer series
    int number =0; //for getting second value
    int bigNumber = 0; //getting number after getting second value
    int smallNumber =0; //getting number after getting second value

    //get 1st values for integer series
    System.out.println( "Enter 1st integer or Enter -99 to end");
    values = keyboard.nextInt();

    if ( values == -99) //to end firstly
    {
    System.out.println( "small Number =" );
    System.out.println( "big Number = " );
    }
    else
    {
    //to get -99
    System.out.println( "Enter 2nd integer or Enter -99 to end");
    number = keyboard.nextInt();
    if ( (number == -99) && (values >= 0))
    {
    System.out.println( "big Number = " + values);
    System.out.println( "small Number =" + values );
    }
    else
    if ( (number == -99) && (values <= 0))
    {
    System.out.println( "big Number = " + values);
    System.out.println( "small Number =" + values );
    }

    //to get second integer value
    if ( (number > values) && (number != -99) )
    {
    bigNumber = number; //from 2nd value
    smallNumber = values; //from 1st value
    }
    else
    if ( (number < values) && (number != -99) )
    {
    smallNumber = number; //from 2nd value
    bigNumber = values; //from 1st value
    }
    }


    //add values until -99 is entered
    while ( (smallNumber != -99) || (bigNumber != -99) )
    {

    if ( (bigNumber > smallNumber) && (bigNumber != -99) )
    {
    System.out.println( "Enter value or -99 to end");
    bigNumber = keyboard.nextInt();
    System.out.println( "<big number given from its 1st if>");
    if ( (bigNumber >= bigNumber) && (bigNumber != -99) )
    {
    System.out.println( "Enter value or -99 to end");
    bigNumber = keyboard.nextInt();
    System.out.println( "<big number given from its 2nd if>");
    }
    }
    else
    if ( (bigNumber < smallNumber) && (bigNumber != -99) )
    {
    System.out.println( "Enter value or -99 to end");
    smallNumber = keyboard.nextInt();
    System.out.println( "<small number given from its last if>");
    }

    if ( (smallNumber < bigNumber) && (smallNumber != -99) )
    {
    System.out.println( "Enter value or -99 to end");
    smallNumber = keyboard.nextInt();
    System.out.println( "<small number given from its 1st if>");
    if ( (smallNumber <= smallNumber) && (smallNumber != -99) )
    {
    System.out.println( "Enter value or -99 to end");
    smallNumber = keyboard.nextInt();
    System.out.println( "<small number given from its 2nd if>");
    }
    }
    else
    if ( (smallNumber > bigNumber) && (smallNumber != -99) )
    {
    System.out.println( "Enter value or -99 to end");
    bigNumber = keyboard.nextInt();
    System.out.println( "<big number given from its last if>");
    }
    }

    //to end loop

    System.out.println( "small Number =" + smallNumber );

    System.out.println( "big Number = " + bigNumber);

    }

    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: Largest and smallest numbers program

    Removed from How to display largest and smallest numbers entered..?

    Don't post to old dead threads and don't hijack another poster's thread.

    Go through the following:
    Forum Rules
    Guide For New Members
    BB Code List - Java Programming Forum - Learn Java Programming

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. finding largest and smallest integer in array
    By csrLewis93 in forum New To Java
    Replies: 9
    Last Post: 02-18-2013, 04:37 AM
  2. Basic largest/smallest problem
    By Acesplit in forum New To Java
    Replies: 2
    Last Post: 09-21-2011, 02:24 AM
  3. Replies: 12
    Last Post: 09-08-2011, 05:03 PM
  4. Array[] get smallest/largest value
    By bobocheez in forum New To Java
    Replies: 13
    Last Post: 09-09-2010, 11:16 PM
  5. Finding largest and smallest integer
    By mlhazan in forum New To Java
    Replies: 2
    Last Post: 01-12-2008, 10:30 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
  •