Different operation on Array
Hi guys...im having trouble with my subject in school, our professor gave us a problem and it needs Array,..
well our topic is Insert,Search,Delete. I dont know how to insert a data in array and save it so that i can search it again, im using javax.swing,
guys please help me:( thx
Re: How to input items in array
Hello jempot and welcome to the Java Programming Forums!
I hope this example will help you.
Code :
public class Jempot {
public static void main(String[] args) {
//Declare a String Array which can hold 5 items.
String[] myArray = new String[5];
//Populate the Array
myArray[0] = "John";
myArray[1] = "Rosie";
myArray[2] = "Mark";
myArray[3] = "Steve";
myArray[4] = "Natalie";
//Loop through the Array and print its content.
for(int a = 0; a < myArray.length; a++){
System.out.println(myArray[a]);
}
//Print just one Array value
System.out.println("\n" + "myArray[2] value is: " + myArray[2]);
}
}
Re: How to input items in array
ok i got this one thx...
but you already populate it in the array,... im wondering if the user going to input items in it and save it?...what am i going to use if i continually save an item in array??
Re: How to input items in array
Code :
import java.io.*;
public class ArrayRead
{
public static void main(String[] az)throws IOException
{
String s[]=new String[5];
System.out.println("Enter theStrings");
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
for(int i=0;i<5;i++)
s[i]=b.readLine();
for(int i=0;i<5;i++)
System.out.println(s[i]);
}
}
Re: How to input items in array
Quote:
Originally Posted by
jempot
ok i got this one thx...
but you already populate it in the array,... im wondering if the user going to input items in it and save it?...what am i going to use if i continually save an item in array??
Take a look at vigneswaras example. Good work.
He is using a buffered reader to take user input from the console.
This can also be done using the Scanner class. Here is an example:
http://www.javaprogrammingforums.com...ner-class.html