Results 1 to 3 of 3
  1. #1
    LasseA is offline Member
    Join Date
    Oct 2012
    Posts
    29
    Rep Power
    0

    Default String - substring and toUpperCase in same println.

    I'm trying to do this selfcheck from my java learning book:
    Consider the following String:
    String quote = "Four score and seven years ago";
    What expression produces the new String "SCORE"? What expression produces "four years"?

    This is my failed attempt:
    Java Code:
    public class SelfCheck_3_15 {
        public static void main(String[] args) {
            String quote = "Four score and seven years ago";
            System.out.println(quote.substring(5, 10) + quote.toUpperCase());
            System.out.println(quote.substring(0, 4) + " " + quote.substring(21, 26));
        }
        
    }
    I guess I'm supposed to do each line, with only use of a single println statement. At least that's what I'm trying to, but failing at.

    Well I can see why it's not working, but what should I change to make it work?

  2. #2
    arieltal is offline Member
    Join Date
    Sep 2012
    Posts
    34
    Rep Power
    0

    Default Re: String - substring and toUpperCase in same println.

    you should do something like quote.substring(5,10).toUpperCase()

  3. #3
    LasseA is offline Member
    Join Date
    Oct 2012
    Posts
    29
    Rep Power
    0

    Default Re: String - substring and toUpperCase in same println.

    Thanks! It's working now, and also I can see that is actually way more simple and easy to remember, than if it was anything like my own attempt.

Similar Threads

  1. Searching for a substring within a String
    By Tryx in forum New To Java
    Replies: 7
    Last Post: 07-16-2012, 08:12 PM
  2. A string and substring problem
    By calnastic in forum New To Java
    Replies: 4
    Last Post: 07-18-2011, 09:02 PM
  3. How do I remove a substring from a string?
    By Unnel in forum New To Java
    Replies: 16
    Last Post: 07-11-2011, 11:56 AM
  4. Search Substring in String Help Please
    By Kestrel01 in forum New To Java
    Replies: 3
    Last Post: 10-26-2010, 06:48 PM
  5. String substring function
    By ravian in forum New To Java
    Replies: 6
    Last Post: 01-02-2008, 07:35 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
  •