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 6 of 6

Thread: What wrong with my code

  1. #1
    Junior Member
    Join Date
    Jan 2019
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default What wrong with my code

    class Simple
    {  
    public static void main(String args[])
    {
    //this is start
    String str = "1944593030303030ff0000148b010600";
    int length = str.length();
    int i = length / 2;
    int i2 = 0;
    String substring = str.substring(0, i);
    str = str.substring(i, length);
    String replaceAll = substring.replaceAll("[^\\d.]", "");
    str = str.replaceAll("[^\\d.]", "");
    long parseLong = Long.parseLong(replaceAll);
    long parseLong2 = Long.parseLong(str);
    str = new StringBuilder();
    str.append(((parseLong + parseLong2) + ((long) length)) / 2);
    str.append("");
    str = str.toString();    //error begin from here
    length = str.length();
    if (length > 8) {
    i2 = length - 8;
    }
    replaceAll = "QW5RE45ReVvcx40gfG8BGHTkKLlRr";
    while (i2 < length) {
    int i3 = i2 + 1;
    i2 = Integer.parseInt(str.substring(i2, i3));
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(str2);
    stringBuilder.append(replaceAll.substring(i2, i2 + 1));
    str2 = stringBuilder.toString();
    stringBuilder = new StringBuilder();
    stringBuilder.append(str2);
    i2 *= 2;
    stringBuilder.append(replaceAll.substring(i2, i2 + 1));
    str2 = stringBuilder.toString();
    i2 = i3;
    }
    return str2;
    System.out.println("sucess");  
    //this is end
    }  
    }

    Output
    Compile by: javac Simple.java
    52.105/Simple.java:19: error: ';' expected
    str = new StringBuilder("") ^
    1 error
    Last edited by nabinprd; January 31st, 2019 at 10:47 AM. Reason: for correction because of I am Beginner.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: What wrong with my code

    Why do you think there is anything wrong with the code?
    If there are error messages, copy the full text and paste it here.
    If the output is wrong, post it and explain.

    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.

  3. #3
    Junior Member
    Join Date
    Jan 2019
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: What wrong with my code

    Thanks friends, I have edited post.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: What wrong with my code

    What happened to the code's formatting? None of the statements are indented. Indentation is important to show the nesting level of statements.
    Look at posted code in other threads on the forum for examples.
    Please post code with proper indentations.

    52.105/Simple.java:19: error: ';' expected
    str = new StringBuilder("") ^
    The compiler is saying that it expects a ; at the end of the statement. Statements need to end with a ;
    Add a ; where the compiler is saying it should be placed.

    Also please post the code (properly formatted) that had the posted error message. The posted code does not include a statement with StringBuilder("") shown in the error message. Note the "" argument
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member tonya's Avatar
    Join Date
    Feb 2018
    Posts
    16
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: What wrong with my code

    I think your statement below may be causing a problem, it is assigning a 'Stringbuilder' object to a 'String' ... you also have other errors around the 'str2' statements further down in your code
    str = new StringBuilder();
    Last edited by tonya; February 5th, 2019 at 10:44 PM.

  6. #6
    Member
    Join Date
    Sep 2018
    Location
    Virginia
    Posts
    284
    My Mood
    Cool
    Thanks
    0
    Thanked 38 Times in 36 Posts

    Default Re: What wrong with my code

    True. But the OP has lots of problems. For example, the following does not make sense whether str is
    a String or an instance of StringBuilder.

    str = str.toString(); //error begin from here

    The OP needs to clean up the code, correct the indents. and show us all the error messages.

    Regards,
    Jim

Similar Threads

  1. what's wrong with this code ?? HELP
    By Roosh in forum What's Wrong With My Code?
    Replies: 7
    Last Post: June 14th, 2014, 10:35 AM
  2. There are something wrong with my code...
    By khanhnq in forum Object Oriented Programming
    Replies: 0
    Last Post: January 13th, 2013, 09:04 PM
  3. What is wrong with my code ?
    By rajarshi in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 11th, 2013, 10:54 PM
  4. what is wrong with my code
    By BLUEJ in forum Java Theory & Questions
    Replies: 4
    Last Post: January 11th, 2013, 04:40 PM
  5. What is Wrong with my code
    By xew123 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 8th, 2011, 04:59 AM

Tags for this Thread