# How can I see full program

• 05-13-2012, 09:07 PM
keki
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
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);                         }                 }         } }```
• 05-13-2012, 10:00 PM
Sierra
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.
• 05-14-2012, 04:52 PM
keki
Re: How can I see full program
any way how to write the code for the wait key
• 05-14-2012, 05:35 PM
Sierra
Re: How can I see full program
You can for example try with
Code:

`System.in.read()`
or read on KeyListeners for more sophisticated control over the key input. :8):
• 05-14-2012, 07:49 PM
DarrylBurke
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
• 05-14-2012, 09:01 PM
JosAH
Re: How can I see full program
Quote:

Originally Posted by DarrylBurke
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.
• 05-14-2012, 09:20 PM
DarrylBurke
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
• 05-14-2012, 09:28 PM
JosAH
Re: How can I see full program
Quote:

Originally Posted by DarrylBurke
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
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)
• 05-14-2012, 11:18 PM
Sierra
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. ^^