Results 1 to 4 of 4

Thread: Compare a char

  1. #1
    Torgero is offline Member
    Join Date
    Oct 2008
    Posts
    33
    Rep Power
    0

    Default Compare a char

    How do I do it?

    Tried this:

    PHP Code:
    import javax.swing.JOptionPane;
    class test {
      public static void main(String[] args) {
    
    char secretChar = "n";
    
         String tekst2 = JOptionPane.showInputDialog("Put in character:");
    	 char inChar = tekst2.charAt(0); // vi tar første tegn
    
    
        if(secretChar == inChar){
        System.out.println("Right.");
    
    	}else{
    
    	System.out.println("Wrong.");
    	}
    	System.out.println("Du la inn tegnet: " + inChar + " , det hemmelige tegnet var: " + secretChar + ".");
    
      }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Please note the different types of quotes that can be used with Java. Single quotes denote chars and double denotes Strings. For eg,
    Java Code:
        //char secretChar = "n"; // this means "n" is a String
        char secretChar = 'n'; // here 'n' is a char

  3. #3
    Torgero is offline Member
    Join Date
    Oct 2008
    Posts
    33
    Rep Power
    0

    Default

    Cheers!! Thanks alot. :)

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Were all problems that easy to solve! Glad you've got it working.

Similar Threads

  1. drawing char by char with Graphics
    By diggitydoggz in forum New To Java
    Replies: 5
    Last Post: 12-27-2008, 01:49 PM
  2. How to Compare two Dates
    By Java Tip in forum java.util
    Replies: 1
    Last Post: 06-24-2008, 08:05 AM
  3. Compare 5 numbers
    By Snowboardmylife in forum New To Java
    Replies: 5
    Last Post: 04-15-2008, 08:04 PM
  4. Compare 2 XML
    By Peter in forum XML
    Replies: 1
    Last Post: 07-05-2007, 03:58 AM
  5. compare speed
    By bbq in forum JDBC
    Replies: 1
    Last Post: 06-28-2007, 06:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •