Results 1 to 2 of 2
Thread: need help linking the array
- 03-22-2010, 11:46 AM #1
Member
- Join Date
- Mar 2010
- Posts
- 14
- Rep Power
- 0
need help linking the array
hi I'm new to java and I've never used an array from another class
well I got this class called wordguesser which is my main class
and I need to link it to this array so that if the user enters a word that is in the array it will show a messege that says you wonJava Code:import java.util.*; // this is the class public class WordGuesser { private InputReader input; private words arraylist; public static String word = null; public void main() { reader = new InputReader(); String inputLine= reader.nextline(); System.out.println("guess the word?"); word = input.nextLine(); } if (get.words == word){ System.out.println ("you won"); } while (get.words != word){ System.out.println ("you lost"); word = input.nextLine(); } } } }
but if its not it will say you lost
this is the array
Java Code:public class words { public static void main(String[] args) { String [] words; // declares an array of integers words = new String [15]; // allocates memory for 10 integers words[0] = "hello"; // initialize first element words[1] = "car"; // initialize second element words[2] = "dog"; words[3] = "plane"; words[4] = "plant"; words[5] = "help"; words[6] = "job"; words[7] = "java"; words[8] = "blue"; words[9] = "bathroom"; words[10] = "word"; words[11] = "apple"; words[12] = "orange"; words[13] = "paper"; words[14] = "stone"; } }
- 03-22-2010, 01:05 PM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Create a public method in words, and pass a bool value to satisfaction. Then call that method from the other class.
Similar Threads
-
Linking Jframes
By nonabhai in forum AWT / SwingReplies: 2Last Post: 03-04-2010, 02:44 PM -
linking to a web page
By Juuno in forum Advanced JavaReplies: 7Last Post: 05-01-2009, 02:47 PM -
static linking
By Nicholas Jordan in forum Advanced JavaReplies: 35Last Post: 03-14-2009, 09:17 PM -
linking 2 Jframes
By suhaib1thariq in forum New To JavaReplies: 9Last Post: 02-13-2009, 01:30 AM -
Linking of exe files
By archu2friends in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 02-06-2008, 06:08 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks