Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-05-2007, 02:20 PM
Member
 
Join Date: Oct 2007
Posts: 9
smilejava is on a distinguished road
input placed in array
im working on this exercise of mine, trying to do the interface,i already made it without the array.. but when i tried to add array(list of wannabee) the Buffered reader is not working anymore.. here's the code....

Code:
package sampInterface; import java.io.*; public class Main { int y = 0; public static void main(String[] args) throws IOException { Artist smile = new Artisttalent(); Main smile2 = new Main(); smile2.wannabees(); audition(smile); } static void audition(Artist s) { s.act(); s.dance(); s.sing(); } public void wannabees() throws IOException { // TODO Auto-generated method stub BufferedReader takeone = new BufferedReader(new InputStreamReader( System.in)); System.out.println("Enter wannabee:"); String[] aspiring; aspiring = new String[5] ; int i = 0; for (y = i; y >= aspiring.length; y++) { aspiring[i] = takeone.readLine(); System.out.println("take one! " + aspiring[y] + " action!"); } } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-05-2007, 09:13 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Code:
public void wannabees() throws IOException { BufferedReader takeone = new BufferedReader( new InputStreamReader(System.in)); System.out.println("Enter wannabee:"); String[] aspiring; aspiring = new String[5] ; int i = 0; for (y = i; y >= aspiring.length; y++) { // The value of "i" is always zero. // You may want to use the variable "y" to select the // array elements for initialization, viz, "aspiring[y]" // in this next line. aspiring[i] = takeone.readLine(); System.out.println("take one! " + aspiring[y] + " action!"); } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-06-2007, 05:22 AM
Member
 
Join Date: Oct 2007
Posts: 9
smilejava is on a distinguished road
but it doesnt allow me to enter anything..

i've changed the code from

Code:
aspiring[i] = takeone.readLine();
to

Code:
aspiring[y] = takeone.readLine();
as what i've understand from what you've told me..
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 11-07-2007, 01:34 PM
Member
 
Join Date: Nov 2007
Posts: 3
JavaThinker is on a distinguished road
The for condition needs a look
Hi,

I think the for condition should be changed to...

for (y = i; y < aspiring.length; y++)

Regards,
JavaThinker
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 11-08-2007, 06:35 AM
Member
 
Join Date: Oct 2007
Posts: 9
smilejava is on a distinguished road
thanks javathinker now it allows me to do so..

but then, im getting into confusion with what i am doing.. i want the array to store 3 wannabees.. but then, what the FOR LOOP is doing was, it just doing the statement again and i know that.. but what i want to happen is, like in 3 times (because of the size of the array), i would enter wannabee and perform the audition method then enter another then perform it again and so on... and the end i would like to Display all the wannabees, but how would i do that?!!

here's my revised code:

Code:
package sampInterface; import java.io.*; public class Main { int y = 0; public static void main(String[] args) throws IOException { Artist smile = new Artisttalent(); Main smile2 = new Main(); String[] listaspiring; listaspiring = new String[3] ; int i = 0; for (int y = i; y < listaspiring.length; y++) { smile2.wannabees(); audition(smile); } } static void audition(Artist s) { s.act(); s.dance(); s.sing(); } public void wannabees() throws IOException { // TODO Auto-generated method stub BufferedReader takeone = new BufferedReader(new InputStreamReader( System.in)); String[] aspiring; aspiring = new String[1] ; for(int i = 0; i < aspiring.length; i ++){ System.out.println("Enter wannabee:"); aspiring[i] = takeone.readLine(); System.out.println("take one! " + aspiring[i] + " action!"); System.out.println(aspiring[i]); } } }
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 11-12-2007, 09:29 AM
Member
 
Join Date: Oct 2007
Posts: 21
unhurt is on a distinguished road
then... u can't use for loop, a loop while will work in ur condition...
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
skipping input windie_86 New To Java 1 02-12-2008 09:09 PM
cant take input from user new_1 New To Java 6 12-25-2007 09:38 AM
input placed in array smilejava New To Java 1 11-05-2007 02:32 PM
beginner needs help with OBD-II input andrewos New To Java 3 07-30-2007 11:46 AM
how to take input and verify input in Java programs bilal_ali_java Advanced Java 0 07-21-2007 10:46 AM


All times are GMT +3. The time now is 11:06 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org