Results 1 to 6 of 6
  1. #1
    smilejava is offline Member
    Join Date
    Oct 2007
    Posts
    9
    Rep Power
    0

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

    Java 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!");
    		}
    	}
    }

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java 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!");
        }
    }

  3. #3
    smilejava is offline Member
    Join Date
    Oct 2007
    Posts
    9
    Rep Power
    0

    Default

    but it doesnt allow me to enter anything.. :confused:

    i've changed the code from

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

    Java Code:
    aspiring[y] = takeone.readLine();
    as what i've understand from what you've told me..

  4. #4
    JavaThinker is offline Member
    Join Date
    Nov 2007
    Posts
    3
    Rep Power
    0

    Default 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

  5. #5
    smilejava is offline Member
    Join Date
    Oct 2007
    Posts
    9
    Rep Power
    0

    Default

    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:

    Java 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]);
    		}
    	}
    }

  6. #6
    unhurt is offline Member
    Join Date
    Oct 2007
    Posts
    21
    Rep Power
    0

    Default

    then... u can't use for loop, a loop while will work in ur condition...

Similar Threads

  1. skipping input
    By windie_86 in forum New To Java
    Replies: 1
    Last Post: 02-12-2008, 08:09 PM
  2. cant take input from user
    By new_1 in forum New To Java
    Replies: 6
    Last Post: 12-25-2007, 08:38 AM
  3. input placed in array
    By smilejava in forum New To Java
    Replies: 1
    Last Post: 11-05-2007, 01:32 PM
  4. beginner needs help with OBD-II input
    By andrewos in forum New To Java
    Replies: 3
    Last Post: 07-30-2007, 10:46 AM
  5. how to take input and verify input in Java programs
    By bilal_ali_java in forum Advanced Java
    Replies: 0
    Last Post: 07-21-2007, 09:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •