Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Bigger and Smaller

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Bigger and Smaller

    I am trying to write a program that reads an integer N that indicates the number of following inputs. The program then reads N integer values (larger than -999999 and smaller than 999999), finds the largest and the smallest values, and prints them. I don't fully understand this question and am left scratching my head as to what to do. Does anyone have any pointers for me?


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Bigger and Smaller

    I would suggest reading this: Language Basics (The Java Language).

    I would also suggest reading Numbers and Strings (The Java Language).

    For reading in an integer, the simplest way is to use the Scanner class.

    Scanner reader = new Scanner(System.in);
    int myInteger = reader.nextInt();

    Once you have the integer, you can use the control structures talked about in the first link to determine if the number is within the correct range, and also figure out the min/max.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Bigger and Smaller

    I don't fully understand this question
    The problem has several points:
    reads an integer N
    The program then reads N integer values
    The values are checked to be between some values...
    finds the largest value entered
    finds the smallest value entered
    prints the two values

    Which ones don't you understand.

  4. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: Bigger and Smaller

    Following on from helloworlds example:

    import java.util.Scanner;
     
    public class BiggerAndSmaller {
     
    	public static void main(String args[]){
     
    		Scanner reader = new Scanner(System.in);
     
    		System.out.println("Enter first number: ");
    		int myIntegerA = reader.nextInt();
     
    		System.out.println("Enter second number: ");
    		int myIntegerB = reader.nextInt();
     
     
    		System.out.println(myIntegerA);
    		System.out.println(myIntegerB);		
    	}
     
    }

    Take a look at: The if-then and if-then-else Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Bigger and Smaller

    Following on from JavaPF's code:
            System.out.println("IntegerA=" +  myIntegerA);
            System.out.println("IntegerB= " + myIntegerB);

    Iding the output can make it more readable.

Similar Threads

  1. Replies: 0
    Last Post: May 25th, 2010, 08:19 AM
  2. 2D Object makes my object smaller, Why?
    By MassiveResponse in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 15th, 2010, 02:33 PM