I want to store names and marks in an array. I am confused what should be the code
import java.util.Scanner;
public class InputArray
{
public static void main(String[]args)
{
String name = "";
{
Scanner ScanObj = new Scanner(System.in);
for(int i = 1 ; i < 6 ; i ++)
{
System.out.println("Enter a name: ");
name = ScanObj.next();
}
String temp += name;
System.out.println("The names you entered are:" + name);
}
}
}
Re: I want to store names and marks in an array. I am confused what should be the cod
Re: I want to store names and marks in an array. I am confused what should be the cod
Quote:
Originally Posted by
newbie
I dont want to hard code it. I know that you can have 2 arrays, one of string type to store names and the other of int type for the marks and then you can display them using the index of the element of any particular array.
However I want the array to ne dynamic and it should be filled by the user and not hard coded. What is the best way to go about it. I want to use arrays and not array lists.
Re: I want to store names and marks in an array. I am confused what should be the cod
To assign a value to an element in an array you code something like this:
anArray[ix] = theValue; // set the element at ix to theValue
Then vary the value of ix to move from one element to the next.
Re: I want to store names and marks in an array. I am confused what should be the cod