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: Hi There

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Hi There

    I am here to learn and share some new and cool stuffs
    Since I am a rookie I will start with a problem

    I have this problem

    When the program starts, you will be
    asked to input an amount of numbers to for your calculations. This can be any number of
    numbers. No matter what number you put in, it should ask you for that amount of numbers.
    For instance, if you put in 100, you will be expected to put in 100 numbers. Once you put in the
    total numbers for use, your program should ask you for each number, while displaying how
    many numbers you have put in and how many you have left to go. At the end, the program
    should be able to show you the Sum, Difference, Product, and the average of all your numbers

    This is my code so far ( it doesn't give me the proper result)

    package javaapplication13;
    import java.util.Scanner;


    public class JavaApplication13 {
    /** Main method */
    public static void main(String[] args) {
    // Create a Scanner
    Scanner input = new Scanner(System.in);

    // Read an initial data
    System.out.print( "Enter a number of numbers to use in your calculation ");
    int data = input.nextInt();

    // Keep reading data until the input equals number of numbers
    int sum = 0;
    while (data !=0) {
    sum += data;

    // Read the next data
    System.out.print(
    "You have entered 0 numbers you have 5 numbers left to enter ");
    data = input.nextInt();


    System.out.println("All numbers added together equal " + sum);
    System.out.println("All numbers subtracted from each other equal " + sum);
    System.out.println("All numbers multiplied6 together equal " + sum);
    System.out.println("All numbers added together equal " + sum);
    }
    }
    }

  2. #2
    Junior Member
    Join Date
    Aug 2012
    Posts
    5
    My Mood
    Bored
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Hi There

    I hope you meant something like this:
    int amountNums = Integer.parseInt(JOptionPane.showInputDialog("Ente r a number of numbers to use in your calculation "));

    // Keep reading data until the input equals number of numbers
    double add = 0.0;
    double subtract = 0.0;
    double multiplied = 1.0;
    double average = 0.0;
    for (int i = 1; i <= amountNums; i++) {
    int number = Integer.parseInt(JOptionPane.showInputDialog("Numb er please:"));
    add = add + number;
    subtract = subtract - number;
    multiplied = multiplied * number;
    }
    average = add / amountNums;

    System.out.println("All numbers added together equal " + add);
    System.out.println("All numbers subtracted from each other equal " + subtract);
    System.out.println("All numbers multiplied together equal " + multiplied);
    System.out.println("The average is: " + average);

  3. The Following User Says Thank You to Gavin Fraser For This Useful Post:

    Mjanja (September 9th, 2012)