Results 1 to 7 of 7
Thread: chars
- 09-28-2008, 06:04 PM #1
Member
- Join Date
- Sep 2008
- Posts
- 29
- Rep Power
- 0
chars
How do i do an if statement about chars?
as if...
The if statements are what is annoying me.Java Code:import java.util.Scanner; public class chars { public static void main( String args[] ) { String name1; String name2; int points1; int points2; Scanner input = new Scanner(System.in) System.out.println( "What is your name?" ); name1 = input.next(); [B] if ( name1 = Jerry )[/B] { points1 = points1 + 1; } System.out.println( "Whats your opponents name?" ) name2 = input.next(); [B] if ( name2 = CPU )[/B] { points2 = points2 + 1; } } }
I cant make it so it'll take the char....
thanks
-
Have you tried something like:
Java Code:if (name1.equals("Jerry")) { //.... }
- 09-28-2008, 06:22 PM #3
Member
- Join Date
- Sep 2008
- Posts
- 29
- Rep Power
- 0
oh darn, srry i tried that but forgot the () around jerry, but shouldn't there be another way to do that?
- 09-28-2008, 06:24 PM #4
Member
- Join Date
- Sep 2008
- Posts
- 29
- Rep Power
- 0
also how would i do a defult, like make the defult Jerry so the user would have to delete the chars?
- 09-29-2008, 05:52 AM #5
- 10-03-2008, 01:03 PM #6
Member
- Join Date
- Oct 2008
- Posts
- 24
- Rep Power
- 0
you cant compare strings with ==
only characters.
use compareTo or equals method.
- 10-03-2008, 09:40 PM #7
Member
- Join Date
- Sep 2008
- Posts
- 29
- Rep Power
- 0
Similar Threads
-
writting extended ascii chars on socket........or Endianness Issue......??
By sachinj13 in forum Threads and SynchronizationReplies: 8Last Post: 09-23-2008, 02:20 PM -
Can we append more than 255 chars to <a href>??
By freddieMaize in forum Advanced JavaReplies: 22Last Post: 07-18-2008, 04:04 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks