Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: assignment help

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default assignment help

    I am lost on this code, I have been trying to get this assignment done and I need help, could someone fix my code please??

    "Write a Java application to do the following:

    a. Allow a user to specify the number of integers to be input into an array.
    b. Read a data set of the specified number of integers into the array.
    c. Determine the sum of the integers in the array.
    d. Next … loop through the items in the array and find the largest integer in the array (negative integers should be accommodated).
    e. Next … loop through the items in the array and determine how many times the largest integer is in the array.

    The output of a application run should include the sum of the integers in the array, the largest integer in the array, the number of times the largest integer is in the array."



    import java.util.Scanner;

    public class bigcount
    {

    public static void main(String args[])
    {

    int w = 0;
    int f = 0;
    int count = 0;
    int sum = 0;
    int large = 0;

    int dataset[] = new int[ datasetSize ];
    int datasetSize = input.nextInt();
    dataset[i] = input.nextInt();

    for (int i=0 ; i<dataset.length; ++i) {

    }
    Scanner input = new Scanner(System.in);
    System.out.print("Welcome to the Big Count Program. \nHow many integer in the dataset: ");
    w = input.nextInt();

    if (w > 0){

    for( count=0; count<w ;count ++)
    {

    if (count==0){
    System.out.println("Enter the integer in the dataset, one per line");
    f= input.nextInt();
    large = f;
    sum=f;
    }

    else{
    System.out.println("");
    f=input.nextInt();
    sum += f;

    if(f>large )

    count++;
    if(w<large )
    large=w;

    }

    System.out.print("The sum of the integers in the dataset is " +sum);
    System.out.println();
    System.out.print("The largest integer in the dataset is " +large);
    System.out.println();
    System.out.print("It appeared in the dataset" +count+ "time(s)");
    System.out.println("Press any key to continue . . .");
    }
    }}}



    also, what file type should I save it as?


  2. #2
    Junior Member
    Join Date
    Oct 2011
    Posts
    20
    Thanks
    1
    Thanked 4 Times in 4 Posts

    Default Re: assignment help

    It would help if you could tell us the problem with your code.

    - First of all, isnt there any problem with declaring "int dataset[] = new int[ datasetSize ]; " before declaring "datasetSize"?

    - There is this loop
    for (int i=0 ; i<dataset.length; ++i) {
     
    }
    Scanner input = new Scanner(System.in);
    System.out.print("Welcome to the Big Count Program. \nHow many integer in the dataset: ");
    w = input.nextInt();
    The "for" closes before the whole Scanner input, so basically thats an useless loop. Check that.

    - Again, it would help if you could mention the problems you're having at the moment.

Similar Threads

  1. Really need help on assignment
    By coorscollector in forum Java Theory & Questions
    Replies: 2
    Last Post: January 16th, 2012, 06:08 PM
  2. assignment troubles polymorphism (guide for assignment included)
    By tdawg422 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 8th, 2011, 10:01 AM
  3. Assignment
    By Polly2010 in forum Java Theory & Questions
    Replies: 3
    Last Post: November 30th, 2010, 03:42 PM
  4. Help with assignment
    By NPVinny in forum What's Wrong With My Code?
    Replies: 12
    Last Post: July 3rd, 2010, 05:31 PM
  5. Replies: 1
    Last Post: February 22nd, 2010, 08:20 AM