1 Replies - 3744 Views - Last Post: 07 March 2007 - 07:39 PM Rate Topic: -----

#1 eric112490   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 07-March 07

User Input

Posted 07 March 2007 - 06:32 PM

 


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...

Is This A Good Question/Topic? 0
  • +

Replies To: User Input

#2 Amadeus   User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 253
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: User Input

Posted 07 March 2007 - 07:39 PM

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:
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...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1