Results 1 to 9 of 9
Like Tree2Likes
  • 2 Post By Sierra

Thread: How can I see full program

  1. #1
    keki is offline Member
    Join Date
    Apr 2012
    Posts
    6
    Rep Power
    0

    Default How can I see full program

    Hi, my assignment is to build an array of 10,000 random numbers (0 to 500).
    Then find average, first print number of instances where array > average, and then print all array numbers together with their array position that are higher than avarage.

    Program should give the following:

    1. average
    2. instances higher than average
    3. array number > average with its array pos.

    The program actually works. The problem is that when I run it the first part of the program does not remain visible and I cannot scroll to see the average, etc.

    any help. below is the code
    Java Code:
    import java.io.*;
    import java.util.*;
    
    
    class ArrayRnd
    {
    	public static void main (String args[])
    	{
    		int total = 0;
    		int average = 0;
    
    		int[] arr = new int[10000]; 			//Array for 10,000 elements from 0 to 500.
    
    		for (int k =0; k<10000; k++){
    			arr[k] = (int)(Math.random() * (501));
    			total +=arr[k];
    			}
    
    		System.out.println();					//Calcualting and displaying average.
    		average = total / 10000;
    		System.out.println("The average value is " + average+ ".");
    
    		int count = 0;						// Count the number of values that were above average.
    		for (int k = 0; k < 10000; k++){
    			if (arr[k] > average)
    			count++;
    			}
    
    		//Print instances where array number > average (occurences).
    		System.out.println("\nThere are " + count + " instances which are higher than average. \n");
    
    		//Print all array numbers, together with their positions, higher than average.
    		System.out.println("\nNumbers higher than average with their position in array:");
    		for (int k = 0; k<10000; k++){
    			if (arr[k] > average){
    				System.out.println(arr[k] + " " + " at position " + k);
    			}
    		}
    	}
    }

  2. #2
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: How can I see full program

    You could either write the output to a file or wait for a key input from the user to go on after the first page.
    DarrylBurke and quad64bit like this.
    I like likes!

  3. #3
    keki is offline Member
    Join Date
    Apr 2012
    Posts
    6
    Rep Power
    0

    Default Re: How can I see full program

    any way how to write the code for the wait key

  4. #4
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: How can I see full program

    You can for example try with
    Java Code:
    System.in.read()
    or read on KeyListeners for more sophisticated control over the key input.
    I like likes!

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

    Default Re: How can I see full program

    For the Windows command prompt:
    -- click the icon at the top left
    -- select Properties
    -- select the Layout tab
    -- increase the height of the screen buffer size

    Haven't checked whether that can go to 10000 lines though. And who's going to read 10000 lines anyway?

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

  6. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,732
    Blog Entries
    7
    Rep Power
    21

    Default Re: How can I see full program

    Quote Originally Posted by DarrylBurke View Post
    And who's going to read 10000 lines anyway?
    A not so thick book (*) contains at least that many lines ...

    kind regards,

    Jos

    (*) book: thin slices of trees filled with ink showing letters in rows.
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

    Default Re: How can I see full program

    Would you read a not-so-thick book whose lines resembled the println outputs in the posted code?

    db

    edit And on reviewing the code, make that 30000 lines

    edit2 Or is it 10002? Difficult to tell with the non-standard bracing and indents
    Last edited by DarrylBurke; 05-14-2012 at 10:22 PM.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  8. #8
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,732
    Blog Entries
    7
    Rep Power
    21

    Default Re: How can I see full program

    Quote Originally Posted by DarrylBurke View Post
    Would you read a not-so-thick book whose lines resembled the println outputs in the posted code?
    Erm ... no, you're right about that ;-)

    Quote Originally Posted by DarrylBurke View Post
    edit And on reviewing the code, make that 30000 lines

    edit2 Or is it 10002? Difficult to tell with the non-standard bracing and indents
    What surprises me is that nobody mentions good old 'more' (or 'less') Are those shell based text tools so outdated already?

    kind regards,

    Jos (<--- fossil)
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: How can I see full program

    Guess there are a hundred ways... though the root cause of the problem is not the viewing I guess. ^^
    I like likes!

Similar Threads

  1. writing full program in one class only
    By ronnie in forum New To Java
    Replies: 3
    Last Post: 03-25-2012, 07:16 PM
  2. Full binary tree
    By Igorock in forum New To Java
    Replies: 5
    Last Post: 12-23-2010, 03:43 PM
  3. how to get the full file name
    By priyanka3006 in forum JDBC
    Replies: 0
    Last Post: 08-05-2009, 01:55 PM
  4. [SOLVED] open a program full size
    By keffie91 in forum Advanced Java
    Replies: 2
    Last Post: 10-05-2008, 11:26 AM
  5. Full screen
    By Jack in forum Advanced Java
    Replies: 2
    Last Post: 07-02-2007, 06:49 AM

Posting Permissions

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