+ Reply to Thread
Results 1 to 2 of 2

Thread: Need Help...Java assignment due today

  1. #1
    Newbie lostgoat is an unknown quantity at this point
    Join Date
    Jun 2009
    Posts
    1

    Question Need Help...Java assignment due today

    I am looking for help in the code at areas with //, please help.
    I am also getting a compiler error with (import java.Date maybe 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 10:18 AM. Reason: add code tags (the # button)

  2. #2
    Code Warrior Turk4n has much to be proud of Turk4n has much to be proud of Turk4n has much to be proud of Turk4n has much to be proud of Turk4n has much to be proud of Turk4n has much to be proud of Turk4n has much to be proud of Turk4n has much to be proud of Turk4n's Avatar
    Join Date
    May 2008
    Location
    4chan.org/g/
    Age
    20
    Posts
    3,836
    Blog Entries
    4

    Re: Need Help...Java assignment due today

    I have done some...
    Now do it a little more...on your own dude...
    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');
    	}
    }
    Cheers !

    Hatsune Miku ~❤❤❤
    初音ミク。~❤❤❤

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Tutorial: Starting Java Using Netbeans
    By Jordan in forum Java Tutorials
    Replies: 4
    Last Post: 02-27-2010, 05:20 PM
  2. need code help, assignment due today
    By kris1976 in forum Java Help
    Replies: 13
    Last Post: 06-29-2009, 07:26 AM
  3. Need Java help due assignment due 6-20
    By kris1976 in forum Java Help
    Replies: 6
    Last Post: 06-21-2009, 01:26 PM
  4. Kill process by command name
    By mop in forum Linux Installation & Configuration
    Replies: 4
    Last Post: 02-16-2009, 07:21 PM
  5. JRuby Co-Developer to conduct Workshop on JRuby, Testing Java with Ruby
    By Shaguf in forum Software Development Tools
    Replies: 1
    Last Post: 12-23-2008, 02:19 PM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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