Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: array to store multiple names and data

  1. #1
    Member
    Join Date
    Apr 2011
    Posts
    32
    Thanks
    20
    Thanked 0 Times in 0 Posts

    Default array to store multiple names and data

    Hello everyone, I realise that i have written in the wrong section, feel free to move my post into the correct section..

    Here is my code below..

     
    import java.util.Scanner;
    public class test{
    public static void main(String args[])
    {
    Scanner input = new Scanner(System.in);
     
    int array[] = new int [5];
    System.out.println("Enter a number");
    	name(array);
     
    	}
     
     
     
    	public static void name(int y[])
    	{
    	Scanner input = new Scanner(System.in);
    	for (int i=0;i<y.length;i++)
    		{
     
    		y[i] = input.nextInt();
    		System.out.println(y[i]);
    		}
     
    	}
     
    }

    What i want to do is increment my variable' i' without the for loop, because i need ask additional questions afterwards...Thanks!
    Last edited by u-will-neva-no; May 1st, 2011 at 11:27 AM.


  2. #2
    Member
    Join Date
    Jan 2011
    Posts
    78
    My Mood
    Confused
    Thanks
    23
    Thanked 1 Time in 1 Post

    Default Re: array to store multiple names and data

    I'm a little confused what your trying to do. Why don't you just use another variable instead of I? Like x and use x++; or just run the whole thing through a while?

  3. The Following User Says Thank You to Hallowed For This Useful Post:

    u-will-neva-no (May 1st, 2011)

  4. #3
    Junior Member
    Join Date
    May 2011
    Posts
    12
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default Re: array to store multiple names and data

    You can move the increment expression out of the for loop, and move it to wherever you want.
    for (int i = 0; i < j; /*empty*/) {
        // ...
        i++;
    }

Similar Threads

  1. Replies: 2
    Last Post: April 21st, 2011, 10:29 AM
  2. How to store objects from a class inn an array?
    By dironic88 in forum Object Oriented Programming
    Replies: 1
    Last Post: April 7th, 2011, 02:42 PM
  3. Read in file and store in 2D array start of The Game of Life
    By shipwills in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 2nd, 2011, 08:52 AM
  4. Read A File and Store Values into a 2-Dimensional Integer Array?
    By Kimimaru in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 9th, 2011, 08:13 PM
  5. Store Values in 2D array and output to textarea
    By raverz1tildawn in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 7th, 2011, 02:13 PM