Welcome to Dream.In.Code
Getting Java Help is Easy!

Join 136,120 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,766 people online right now. Registration is fast and FREE... Join Now!




User Input

 
Reply to this topicStart new topic

User Input

eric112490
7 Mar, 2007 - 05:32 PM
Post #1

New D.I.C Head
*

Joined: 7 Mar, 2007
Posts: 1


My Contributions
CODE



public class Lab6

        {
        public static void main(String[] args)
            {

                double i;
                for ( i=1; i<=10; i++ )
                {



                    System.out.println("Please enter a number: ");

                    System.out.println("Numbers entered in " + i + "");
                }








            }
}





thats i what i have so far.... I am at home right now and trying to work off memory..all my notes are on my schools server...so i dont remember everything...i am trying to make a simple program that you input 10 numbers, you tell them the total amount of numbers youve entered, you tell them their current total, and at the end you finish by telling them the average.

i had the

import.java.util* <<thats not right

and i know about the scanner myinput...


User is offlineProfile CardPM
+Quote Post

Amadeus
RE: User Input
7 Mar, 2007 - 06:39 PM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,226



Thanked: 37 times
Dream Kudos: 25
My Contributions
You'll need a variable at the very least to take input from the user, and I'd suggest using the Scanner class if it's going to be integers. You don't need an array for your purposes...something like the following should suffice:
CODE

Scanner sc = new Scanner(System.in);
int input;
double total = 0;
for (int i=0; i<10; i++ ){
   System.out.println("Please enter a number: ");
   input = sc.nextInt();
   total+= input;
   System.out.println("Running total is " + total);
}
System.out.println("Total is " + total);
System.out.println("Average is is " + (total/10));

You may have to tweak it some...
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 10:04PM

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month