Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Java string manipulation

  1. #1
    Junior Member
    Join Date
    Feb 2021
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java string manipulation

    I am a Java Newbie by the way, please go easy on me!

    What I want to do: If a string is less than 10 characters, add enough characters to make it equal to 10 characters

    My code so far, I know the last few lines especially this one: int theActualLength = 10 - length is probably wrong! and my indentation and closing braces are incorrect, I will fix them later - many thanks in advance!

    public class Sample_String {
    public static void main(String[] args) {
    String newString = "testing";
    int length = newString.length();
    if (newString.length() < 10) {
    int theActualLength = 10 - length
    for(theActualLength = 0; i<10; i++){
    System.out.println("The length of the newString is now: "+theActualLength);
    }
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    24,071
    Thanks
    53
    Thanked 2,614 Times in 2,564 Posts

    Default Re: Java string manipulation

    What happens when the code is compiled and executed?
    Please copy the contents of the console and paste it here with any comments you have about what happened.

    add enough characters
    Where does the code add any characters?

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. [SOLVED] String Manipulation.
    By Praetorian in forum Java Theory & Questions
    Replies: 6
    Last Post: February 19th, 2014, 11:52 AM
  2. string manipulation
    By nhiap6 in forum Java Theory & Questions
    Replies: 2
    Last Post: November 17th, 2012, 06:32 AM
  3. string manipulation
    By nhiap6 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 16th, 2012, 12:28 PM
  4. String Manipulation.
    By Nemus in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 21st, 2011, 03:02 PM
  5. String manipulation help
    By Duff in forum Loops & Control Statements
    Replies: 7
    Last Post: March 19th, 2010, 04:02 AM

Tags for this Thread