Go Back   CodeCall Programming Forum > Software Development > Java Help
Register Blogs Search Today's Posts Mark Forums Read

Java Help Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-22-2009, 10:49 AM
Newbie
 
Join Date: Jun 2009
Posts: 1
lostgoat is an unknown quantity at this point
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 11:18 AM.. Reason: add code tags (the # button)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 06-22-2009, 12:52 PM
Turk4n's Avatar
Code Warrior
 
Join Date: May 2008
Location: 4chan.org/g/
Age: 20
Posts: 3,822
Turk4n has much to be proud ofTurk4n has much to be proud ofTurk4n has much to be proud ofTurk4n has much to be proud ofTurk4n has much to be proud ofTurk4n has much to be proud ofTurk4n has much to be proud ofTurk4n has much to be proud of
Send a message via MSN to Turk4n Send a message via Skype™ to Turk4n
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 ~❤❤❤
初音ミク。~❤❤❤
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


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


All times are GMT -5. The time now is 11:20 AM.


vBulletin v3.8.0 ©2010, Jelsoft Enterprises Ltd.


no new posts

LinkBacks Enabled by vBSEO 3.1.0