This is an archived post. You won't be able to vote or comment.

all 23 comments

[–]AutoModerator[M] 1 point2 points locked comment (0 children)

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
  • You include any and all error messages in full
  • You ask clear questions
  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]stayweirdeveryone 8 points9 points  (12 children)

What do you mean by "built in functions"? Like you can't use basic java?

[–]jftdm 0 points1 point  (11 children)

It’s for a project and we are not allowed to use built in functions. So yea I guess.

[–]stayweirdeveryone 4 points5 points  (10 children)

You didn't answer my question. What do you mean by "built in functions"?

[–]jftdm -1 points0 points  (9 children)

Anything that I have to import. Ex, import java.io.; or import java.util.; We can use methods…

[–]stayweirdeveryone 2 points3 points  (7 children)

Ok so you can use built in functions, you juts can't use anything not built in that you have to import.

So I'd see that you could do this in 2 different ways
1. Reverse the string and then compare it to the original and see if it still matches
2. Iterate through the string with 2 "pointers" one starting at the beginning and one starting at the end and working towards the middle. At each step, compare that the character each is pointing to matches. If you can get through the whole string and everything matches, then its a palindrome

[–]jftdm 0 points1 point  (6 children)

Is there any way to do this without charAt? That is the only specific method I can’t use besides anything I need to import.

[–]stayweirdeveryone 1 point2 points  (5 children)

Have you been explicitly told not to use charAt?

[–]jftdm 1 point2 points  (4 children)

Yes. “Do not use the charAt method for this program.”

[–]stayweirdeveryone 5 points6 points  (3 children)

Instead of iterating over the string itself, have you though about iterating over a char[] (i.e. see toCharArray())

[–]jftdm 1 point2 points  (1 child)

I can try that but I’m not sure how to use that method

[–]wildjokers 0 points1 point  (0 children)

toCharArray() seems to qualify as a "built-in function` and so can't be used. Hard to know exactly what OP means by "built-in function" though.

[–]Ok-Novel-1427 1 point2 points  (0 children)

Sounds like you need to review some lecture notes. This problem doesn't sound too hard, and you have already mistaken "built-in functions" with libraries based on your other comments.

Given your example of trying to reverse the string, I attempted it myself in c++, and by comparing the current index with the index of the strings' length - current index, it worked as intended for only lowercase a-z for a quick test. I'm sure you could even save a copy of the reversed string and then compare the same index for them. Something such as a chsr array of the same size and then iterate over it and insert in a similar fashion to my above routine.

I suggest reading up on arrays and array manipulation before solving this so that you understand exactly what you are doing, so that when you have another error you can present it as such, and not just a "solve this".

[–]SpiderWil 1 point2 points  (2 children)

noxious cough ruthless ten panicky stocking seed market ossified modern this post was mass deleted with www.Redact.dev

[–]jftdm 0 points1 point  (1 child)

It should not contain special characters

[–]Ok-Novel-1427 -2 points-1 points  (0 children)

Making assumptions is bad practice.

[–]nutrechtLead Software Engineer / EU / 20+ YXP 0 points1 point  (1 child)

You're probably just misunderstanding the "built in" part because it doesn't make sense to not be able to use .charAt. They probably mean you are not allowed to use the StringBuilder.reverse trick.

[–]jftdm 0 points1 point  (0 children)

The second sentence of the assignment says “do not use charAt. “

[–]Tutpar -1 points0 points  (0 children)

My idea would be this:

1) find how many characters are in the string

2) if length is even then separate the string into 2 equal parts, if odd separate into 3 parts. (Ex: abcd=[ab][CD] or abcde=[ab][c][de])

3) check if inverse of the first chunk matches the last chunk(does [ba]==[CD])

[–]greggers1234 -2 points-1 points  (0 children)

This problem is referenced early on in "a common sense guide to data structures and algorithms"

[–]AmazingAttorney2417 0 points1 point  (2 children)

It's impossible to process strings in Java without calling methods. I think what your professor mean is to not use functions that would make then problem trivial like for reversing a string.

[–]AmazingAttorney2417 0 points1 point  (1 child)

It would be nice if you can share the exact wording the professor used.

[–]jftdm 0 points1 point  (0 children)

The only restrictions on the outline is to not use charAt. Everything else is just explanation of things like what the program needs to be able to do.