Results 1 to 2 of 2
  1. #1
    dandaryll is offline Member
    Join Date
    Feb 2017
    Posts
    2
    Rep Power
    0

    Question Please Help! Need an expression with limitations as seen on code to detect first char

    So basically my solution can only be in in if statement condition shown below. I am limited and cannot create additional variables or modify data types etc.

    Please help...I tried
    MY FAILED SOLUTION
    Java Code:
    firstLetter.equals(userInput.charAt(0)))
    HERE'S WHAT I'M WORKING ON:
    Java Code:
    public class CharMatching {
       public static void main (String [] args) {
          String userInput = "";
          char firstLetter = '-';
    
          userInput = "banana";
          firstLetter = 'b';
    
          if (/* Your solution goes here  */) {
             System.out.println("Found match: " + firstLetter);
          }
          else {
             System.out.println("No match: " + firstLetter);
          }
    
          return;
       }
    }

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,991
    Rep Power
    8

    Default Re: Please Help! Need an expression with limitations as seen on code to detect first

    firstLetter is of type char which is a primitive and does not have any methods. You can compare chars with == instead of equals().
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

Similar Threads

  1. Convert a String of ASCII Code to Char?
    By Argyros in forum New To Java
    Replies: 3
    Last Post: 08-25-2014, 01:09 PM
  2. Replies: 2
    Last Post: 07-18-2011, 07:11 AM
  3. Help with LCDUI limitations!
    By PeteDesigner in forum New To Java
    Replies: 6
    Last Post: 11-18-2010, 02:10 PM
  4. How get char by code?
    By artemff in forum New To Java
    Replies: 1
    Last Post: 01-01-2010, 11:16 PM
  5. Limitations unneceeasry
    By ranjiths in forum Suggestions & Feedback
    Replies: 1
    Last Post: 09-28-2009, 04:23 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
  •