+ 2
Who helps me with this project invert a string in java
8 Antworten
0
In many circumstances, I'd agree. If it were personal homework, I wouldn't have helped at all. However, Jose has gone through the entire course (among others) and was wanting some assistance. However, I did go back and comment it some so that there is understanding to what was posted. As well, I disagree about it not helping someone. He'll assess why it worked versus not and begin to memorize what he's reading and become familiar with others code. Just like if one already experienced reads through someone else's code (as we do in the industry), they're going to relate what they've already learned/read and assess it against how someone else did it or memorize what one did to accomplish a task. So to assume that it provides no value to him is a short-sighted way to view the situation; especially to assume one won't become better at coding/thinking about problems via viewing others code. I've learned much from reading other people's code over the years, even in the beginning phases of learning. Further, self-learning doesn't mean alone or lonely learning. It simple entails that you're taking the initiative to obtain and study resources on your own; you don't require an institution to force you to learn or instruct you on how/when/what you'll be learning.
Anyways, what "we should do" is a whole other discussion in itself and isn't the same discussion for every individual learner. Regardless, I did go back and add in some comments to add to the educational value of what was posted. Hope that assists toward your personal objective.
+ 3
Jakko Jak , Jose Reinaldo Parra Morales ,
please help us to keep sololearn what it is made for: It is a self-learning platform.
So this means, that we should avoid giving codes when people ask for this, before they have done a try by themselves and before they have present it here. It looks really helpful when you post a code as you did, but it does not help the OP. This will be a copy and paste - and the coding skills and problem solving ability will not grow.
What we should do is to give hints or comments how to solve the task.
Thanks for your understanding.
+ 2
Based on the link you sent, try something like this:
https://code.sololearn.com/cA25A16A5A0A
// java.util.* will allow us to use Scanner for input
import java.util.*;
public class Program
{
public static void main(String[] args) {
// Obtain user input
Scanner scanner = new Scanner(System.in);
// Store user input into String variable
String text = scanner.nextLine();
//Create array to hold individual letters (char)
char[] arr = text.toCharArray();
// Get length of array for max loop iteration
int j = arr.length-1; // -1 so it'll work for 0-based array index
// Set up some display for our data
System.out.println("Original: " + text);
System.out.print("Inverted: ");
for (int i=j; i>=0; i--){
// Start at end of array and loop backwards
// for( start point; condition to end; iteration direction)
// use iteration var (i) as array index to check arr value
System.out.print(arr[i]); // use iteration i for index
}
}
}
::::INPUT:::
SoloLearn
::::OUTPUT::::
Original: SoloLearn
Inverted: nraeLoloS
+ 1
Martin Taylor, no need to agree to disagree when we're saying the same thing for different contexts; it's all objective stuff that neither of us created and is hardly either of our opinions. Inversion is to flip/reverse something. As you said, in the case of binary, that'd be changing a 1 to 0, and vice versa, and even further when you're dealing with other math (such as additive and multiplicative inversion). However, his question wasn't in regards to math or anything on a binary level; it was how to invert a string that's stored as chars in an array. As mentioned in my initial reply, my answer was based on what he asked / based on the context of the link he referenced in his original post; which was on how to invert a string that's stored in an array. In that context, you're simply reversing it.
Definition of invert:
"put upside down or in the opposite position, order, or arrangement."
Either way, thanks for responding and elaborating upon your previous point.
0
OK, bro Lothar
0
Martin Taylor, inverting a string is the exact same thing as reversing it; even per definition on a normal day, it's the process of reversing the order of something. You're the first person I've met that's ever said otherwise, but if you're correct, then I'd love if you provided me resources so that I can further educate myself.
The definition of invert/reverse aside, that's certainly a better way to go about it. I know he was referencing a particular way of doing it via the link, but I believe it's as you said, it's some exercise stemming from the array section and is less about the string than it is about manipulating the array.