Results 1 to 6 of 6
- 03-18-2010, 07:30 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 1
- Rep Power
- 0
Checking if something is equals to anything in an array
My code so far
import java.util.Random;
I am trying to check if rud is equals to anything in rod but it doesnt work any idea on how to solve it ?Java Code:class Test{ public static void main(String[] args){ Random Attack = new Random(); int rud = 0; int rod[]={2,5,4,3,6}; for(int counter=1; counter<=1; counter++){ rud=Attack.nextInt(10); } if(rud==rod[]){ System.out.println("You hit"); System.out.println(rud); }else{ System.out.println("You missed"); System.out.println(rud); } } }
- 03-18-2010, 07:41 PM #2
Major logic flaw. Do it with pencil and paper and I'm sure you'll see it.
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 03-18-2010, 08:56 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
- 03-18-2010, 09:00 PM #4
Your crap-o-meter is broken if it burps on crap!
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 03-18-2010, 09:05 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
- 03-19-2010, 12:26 AM #6
Member
- Join Date
- Mar 2010
- Posts
- 20
- Rep Power
- 0
IŽll write the solution for you, so you can check where you were wrong.
Java Code:class Test{ public static void main(String[] args){ Random Attack = new Random(); int rud = 0; int rod[]={2,5,4,3,6}; int nTries = 5; for(int counter=[B]0[/B]; counter<nTries; counter++){ rud=Attack.nextInt(10); if(rud==rod[counter]){ System.out.println("You hit"); System.out.println(rud); }else{ System.out.println("You missed"); System.out.println(rud); } } } }
Similar Threads
-
== and equals()
By arefeh in forum New To JavaReplies: 13Last Post: 01-05-2010, 04:56 PM -
== is same as .equals()??
By DrMath in forum New To JavaReplies: 1Last Post: 09-30-2009, 04:57 AM -
equals method
By mani_miit in forum Advanced JavaReplies: 7Last Post: 09-09-2009, 10:26 PM -
a little problem with (equals)
By gamilah in forum New To JavaReplies: 5Last Post: 10-25-2008, 04:08 AM -
name clash: equals(E) in and equals(java.lang.Object)
By AdRock in forum New To JavaReplies: 0Last Post: 01-25-2008, 11:13 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks