Results 1 to 5 of 5
- 10-28-2012, 09:11 PM #1
Member
- Join Date
- Oct 2012
- Posts
- 7
- Rep Power
- 0
Using arrays to get user input and display it
Hello.
My assignment is to (using arrays) get user input for several questions and then display them back to the user.
This is an example of what I have come up with so far, but I feel like I'm pretty sure I'm not using arrays the way my professor wants - this program is no more efficient than if I had done it without an array (probably less so because of the extra code).
My professor mentioned using for loops with the arrays, but I just don't know where to go from here...
Thanks in advance.XML Code:public class ClassName { Scanner input = new Scanner (System.in); public String value1; public String value2; public String value3; String Array1 [] = new String [3]; public void methodOne() { System.out.println ("Favorite color? "); value1 = input.nextLine(); Array1[0] = value1; System.out.println ("Favorite food? "); value2 = input.nextLine(); Array1[1] = value2; System.out.println ("Favorite place to visit? "); value3 = input.nextLine(); Array1[2] = value3; System.out.println (Array1[0]); System.out.println (Array1[1]); System.out.println (Array1[2]); }
- MCLast edited by mc54321; 10-28-2012 at 09:21 PM.
- 10-28-2012, 10:09 PM #2
Member
- Join Date
- Mar 2012
- Posts
- 7
- Rep Power
- 0
Re: Using arrays to get user input and display it
i find this guys videos very good. Just seach this channel for java. Good info on loops and iterators
Jose Vidal - YouTube
- 10-29-2012, 05:09 PM #3
Java Apprentice
- Join Date
- Oct 2012
- Location
- On my computer
- Posts
- 10
- Rep Power
- 0
Re: Using arrays to get user input and display it
You could use a loop to cycle through each answer. Here is an example of using a for loop:
/code
for(int i=0;i<3;i++){
System.out.println(Array1[i]);
}
//code
This would output everything in array 0, 1, and 2.
- 10-29-2012, 05:11 PM #4
Java Apprentice
- Join Date
- Oct 2012
- Location
- On my computer
- Posts
- 10
- Rep Power
- 0
Re: Using arrays to get user input and display it
I typed the code thing wrong, and I can't edit it, so here it is again. :P
Java Code:for(int i=0;i<3;i++){ System.out.println(Array1[i]); }
- 10-30-2012, 01:01 AM #5
Member
- Join Date
- Oct 2012
- Posts
- 7
- Rep Power
- 0
Similar Threads
-
Arrays made from user input
By sonofJack3 in forum New To JavaReplies: 15Last Post: 12-01-2011, 06:18 AM -
how to make the check button get user input and display it
By ashraf in forum AWT / SwingReplies: 2Last Post: 09-27-2011, 06:46 PM -
how to pass user input into multi-dimensional arrays
By ziongio in forum New To JavaReplies: 4Last Post: 03-09-2011, 05:54 AM -
How to display queries results from Oracle according to user input?
By NeVerEveR in forum JDBCReplies: 1Last Post: 10-18-2010, 07:14 AM -
Making arrays by reading user input
By apfroggy0408 in forum New To JavaReplies: 23Last Post: 04-30-2008, 01:23 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks