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.

1 Visitor Messages

  1. Hi guys I am facing a problem creating a program using loops
    Here is the 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

    My code look like this( it does not give the required output)

    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);
    }
    }
    }
Showing Visitor Messages 1 to 1 of 1
About Mjanja

Basic Information

About Mjanja
Java Skill Level:
Beginner

Statistics


Total Posts
Total Posts
1
Posts Per Day
0.00
Visitor Messages
Total Messages
1
Most Recent Message
September 8th, 2012 07:47 PM
Total Thanks
Total Thanks
1
  • Thanked 0 Times in 0 Posts
General Information
Last Activity
September 28th, 2012 02:01 PM
Join Date
September 8th, 2012