I am looking for help in the code at areas with //, please help.
I am also getting a compiler error with (import java.Datemaybe this will be cured when other lines are ??
Code:import java.util.Scanner; import java.util.Random; import java.io.*; import java.Date; public class PGM1 { public static void main(String[] args) throws IOException {String fname; Random rrd = new Random(System.currentTimeMillis()); Scanner kbd = new Scanner(System.in); System.out.println("What is the output filename? "); fname = kbd.nextLine(); PrintWriter outfile = new PrintWriter(fname); System.out.println("What's the size of the array? "); int sz = kbd.nextInt(); if(sz < 25 || sz > 100) System.out.println("The array size is out of range." + "Please enter a size between 25-100. "); int [] nums = new int[sz]; System.out.println("Random Numbers: "); System.out.println(); // Fill nums[] with random numbers in the range 0 thru 23456 // Write (to outFile) numbers from nums, 5 to a line - well aligned int highest = nums[0]; for (int index = 1; index < nums.length; index++) { if (nums[index] > highest) highest = nums[index]; } int lowest = nums[0]; for (int indexL = 1; indexL < nums.length; indexL++) { if (nums[indexL] < lowest) lowest = nums[indexL]; } int total = 0; int average; for (int indexA = 0; indexA < nums.length; indexA++) total +=nums[indexA]; average = total/nums.length; System.out.print("Smallest: " + "/t" + lowest); System.out.println("/t/t/tLargest: " + "/t" + highest); System.out.println("Average: " + "/t" + average); // close outFile
Last edited by WingedPanther; 06-22-2009 at 08:18 AM. Reason: add code tags (the # button)
I have done some...
Now do it a little more...on your own dude...
Cheers !Code:import java.io.IOException; import java.io.PrintWriter; import java.util.Random; import java.util.Scanner; public class PGM1 { public static void main(String[] args) throws IOException { String fname; char check; int sz; do { Random r = new Random(); Scanner kbd = new Scanner(System.in); //System.out.println("What is the output filename? "); //fname = kbd.nextLine(); // if(fname.equals(null) || fname.equals("")) { // System.out.println("No file found"); // } //PrintWriter outfile = new PrintWriter(fname); do { System.out.println("What's the size of the array? "+ "\nRemember from 25-100"); sz = kbd.nextInt(); } while(sz < 25 || sz > 100); int [] nums = new int[100]; for(int i=0; i<sz; i++) { nums[i] = r.nextInt(1)+23456; } // Write (to outFile) numbers from nums, 5 to a line - well aligned int highest = 23456; for (int index = 0; index < nums.length; index++) { if (nums[index] > highest) highest = nums[index]; } int lowest = 0; for (int indexL = 0; indexL <nums.length; indexL++) { if (nums[indexL] < lowest) lowest = nums[indexL]; } int total = highest+lowest; int average; for (int indexA = 0; indexA < nums.length; indexA++) total +=nums[indexA]; average = total/nums.length; System.out.println("Random Numbers"); System.out.println("Smallest: "+lowest); System.out.println("Largest: "+highest); System.out.println("Average: "+average); //outfile.close(); System.out.print("Wanna do again?" + "\nYes or No?"); String in = kbd.next(); check = in.charAt(0); } while(check=='y' || check=='Y'); } }
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks