Results 1 to 4 of 4
Thread: util scanner with array
- 03-07-2011, 02:54 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 1
- Rep Power
- 0
util scanner with array
can you give me a more explanation of this?
how can I lope the average of 5 numbers?
example:
import java.util.Scanner;
public class average {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner inputData = new Scanner(System.in);
System.out.println("Enter a number");
int number = inputData.nextInt();
int[]num = new int [5];
int counter;
int ave = 0;
can you give me the whole program.....please...
I am a beginner student....healp me...please..
- 03-07-2011, 03:48 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
If you are a beginner, then start from the basic step. Lets start from the collecting user inputs. So how you can ask user to enter a number 5 times. You've to do something in a loop,
So how you decide the loop runs 5 times and ask the question. Forget about what to do with user inputs at the moment. Give a try and let me know.Java Code:while(...) { // Body of the loop }
- 03-20-2011, 04:48 AM #3
Member
- Join Date
- Mar 2011
- Location
- Bulacan, Philippines
- Posts
- 23
- Rep Power
- 0
import java.util.Scanner;
public class average {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner inputData = new Scanner(System.in);
int[]num = new int [5];
for(int x=0;x<num.length;x++){
System.out.println("Enter a number");
int number = inputData.nextInt();
}
do the logic on your here
}
- 03-23-2011, 08:34 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
And you've to think about a way to store collected data from the user as well. That's all explains that your logic should be inside the loop or not.
Similar Threads
-
java.util.Scanner runs in Vista but not in Linux
By pellebye in forum New To JavaReplies: 6Last Post: 08-24-2009, 03:50 AM -
java.util.Scanner not recognised
By pjm35@st-and.ac.uk in forum New To JavaReplies: 4Last Post: 06-07-2008, 03:32 PM -
Using java.util.Scanner to search for a String in a String
By Java Tip in forum Java TipReplies: 0Last Post: 11-20-2007, 04:59 PM -
Using ava.util.Scanner
By Java Tip in forum Java TipReplies: 0Last Post: 11-20-2007, 04:47 PM -
The import java.util.Scanner cannot be resolved
By Heather in forum Advanced JavaReplies: 1Last Post: 07-08-2007, 01:05 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks