Reverse Strings in JAVA | (simple & easy)

  Рет қаралды 61,164

Mintype

Mintype

Жыл бұрын

Reverse Strings in JAVA | (simple & easy)
In today's video, I will be showing you how to reverse a string in Java!
► Software Used:
● IntelliJ IDEA: www.jetbrains.com/idea/download/
► Helpful Learning Sites:
● Codecademy: www.codecademy.com/
● freeCodeCamp: www.freecodecamp.org/
► Song Used:
● One More Time: • [FREE] Lofi Type Beat ...
► Support or Follow me:
● Join our Discord: / discord
● GitHub: github.com/SmallPlayz
● Twitter: / smallplayz_
● Instagram: / smallplayz_

Пікірлер: 50
@Spider-Man_67
@Spider-Man_67 Жыл бұрын
Very simple & sweet code, thank man!
@mintype
@mintype Жыл бұрын
Glad it helped!
@xebex5451
@xebex5451 4 ай бұрын
thanks man!!
@ajeetkumarsingh1302
@ajeetkumarsingh1302 3 ай бұрын
great video man probably shortest programming video i have watched on youtube. i am new to coding how do i excel in this
@mintype
@mintype Жыл бұрын
If anyone has any other things related to CS or JAVA they want a video on, just reply here! Join the discord! -> discord.gg/hhGu6mV5wm
@armenia18yt3
@armenia18yt3 9 күн бұрын
short and simple, thank you
@mintype
@mintype 6 күн бұрын
You're welcome!
@raykhonayorieva7156
@raykhonayorieva7156 Жыл бұрын
great very simple and very understandable thank you thank you
@mintype
@mintype Жыл бұрын
Glad it was helpful!
@oshadhaedirisinghe1455
@oshadhaedirisinghe1455 4 ай бұрын
Thank you
@bankarsandipk
@bankarsandipk 11 ай бұрын
Nice short explanation 😊
@mintype
@mintype 11 ай бұрын
Glad it was helpful!
@JSR2428
@JSR2428 2 ай бұрын
Why you use that + sign with result?
@renukasp3510
@renukasp3510 Жыл бұрын
Simple and easy 👏
@mintype
@mintype Жыл бұрын
Thanks a lot 😊
@bhaveerathod2373
@bhaveerathod2373 Жыл бұрын
nice
@47lokeshkumar74
@47lokeshkumar74 Жыл бұрын
Nice
@mintype
@mintype Жыл бұрын
Thanks
@kevswags
@kevswags 9 ай бұрын
I think i found an easier way: String s = "123456789"; StringBuilder x = new StringBuilder(s); x.reverse(); String output = x.toString(); System.out.println(output);
@mintype
@mintype 9 ай бұрын
Your way works and is more simple than my way, however this video is supposed to teach those who don’t know how to reverse a sting WITHOUT StringBuilder. (For example in a AP CSA class they would ask you to do this without StringBuilder)
@HorridOnlineTroll
@HorridOnlineTroll 2 ай бұрын
interviews tend to not allow things like StringBuilder, while yes it is more efficient, they want to see if you know the fundamental logic
@alejandroquinonescaicedo8
@alejandroquinonescaicedo8 Жыл бұрын
StringBuilder
@mintype
@mintype Жыл бұрын
StringBuilder is another way you could do this. However, I am teaching how to do this manually, because in schools, teachers don't want you to take shortcuts.
@baseplate_462
@baseplate_462 4 ай бұрын
im not exactly sure i understand why we do .length - 1; what is the -1 for?
@almira4008
@almira4008 4 ай бұрын
-1 means the index of last character, because index starts from zero, so when you want to get last characters' index you should add this -1
@HorridOnlineTroll
@HorridOnlineTroll 2 ай бұрын
array {1, 2, 3, 4, 5} There's 5 elements inside, it has a length of 5. However, if we want to know the index of each element inside the array the value '1' is at position '0' which means element '5' is at position '4', so to get the value '5' we need to write array[4]. given N is the length of the array, n-1 determins the position of those elements. If simple wrote i = str.length; you would get an out of bounds exception element because the element '5' is at position '4', not position '5'. Following the formular n-1, we say str.-length-1 to ensure we always end up at the last element contained within the array.
@ravalimanchala8170
@ravalimanchala8170 Ай бұрын
Thank you for your valuable information
@frailedtea
@frailedtea Ай бұрын
@@HorridOnlineTroll You're amazing!
@chrism2828
@chrism2828 9 ай бұрын
I keep getting an exception out of bounds error and I’m not sure why.
@mintype
@mintype 9 ай бұрын
send ur code here
@pradipacharya3168
@pradipacharya3168 Жыл бұрын
how do u reverse the string itself
@mintype
@mintype Жыл бұрын
you can set the original string variable's value to the result string variable's value like so: str = result;
@pradipacharya3168
@pradipacharya3168 Жыл бұрын
@@mintype what if you wanted to change the string itself inside the loop rather than creating a empty string to store the reversed version on. (thxs for the reply btw, i'm new so that helped)
@mintype
@mintype Жыл бұрын
@@pradipacharya3168 I've done some research and if you wanted to change the string itself inside the loop rather than create an empty string to store the reversed version to, that wouldn't really work. However, this video is to show people how to reverse strings using a for loop, like how they may expect a student to in a computer science class. If you really wanted to reverse a string in less lines of code etc., you could do the following: String originalString = "Hello, world!"; StringBuilder reversedString = new StringBuilder(originalString).reverse(); System.out.println(reversedString); // prints "!dlrow ,olleH"
@pradipacharya3168
@pradipacharya3168 Жыл бұрын
@@mintype thank you man, that helped a lot!
@mintype
@mintype Жыл бұрын
glad it helped!
@4ugaming693
@4ugaming693 Ай бұрын
type mismatch bro
@irisrin
@irisrin 9 ай бұрын
my results came out diffrent
@mintype
@mintype 9 ай бұрын
Can you provide some info? Like give me your code so I can see whats wrong. Also maybe tell me your version of Java? New Java versions come out all the time and can break old code. discord help server: discord.gg/hhGu6mV5wm
@nahidasultana6842
@nahidasultana6842 10 ай бұрын
Hi, I am having an error. what mistake i have made? package Practice; public class HelloReverse { public static void main(String[] args) { String input ="Hello world!"; String output=" "; for(int i=input.length()-1;i>=0;i--); output+=input.charAt(i); System.out.println(output);
@mintype
@mintype 9 ай бұрын
You have a ; (semicolon) at the end of your for loop!!!! updated code: String input ="Hello world!"; String output=" "; for(int i=input.length()-1;i>=0;i--) output+=input.charAt(i); System.out.println(output);
@nahidasultana6842
@nahidasultana6842 9 ай бұрын
@@mintype Thank you so much!
@ravalimanchala8170
@ravalimanchala8170 Ай бұрын
Thank you
@ravalimanchala8170
@ravalimanchala8170 Ай бұрын
Thank you
@ravalimanchala8170
@ravalimanchala8170 Ай бұрын
Thank you
@urboigot45iron4
@urboigot45iron4 Жыл бұрын
nice
@mintype
@mintype Жыл бұрын
Thanks
Enhanced For Loops in JAVA | (simple & easy)
1:46
Mintype
Рет қаралды 7 М.
Wait for the last one! 👀
00:28
Josh Horton
Рет қаралды 152 МЛН
孩子多的烦恼?#火影忍者 #家庭 #佐助
00:31
火影忍者一家
Рет қаралды 48 МЛН
КАРМАНЧИК 2 СЕЗОН 7 СЕРИЯ ФИНАЛ
21:37
Inter Production
Рет қаралды 525 М.
Coding Was Hard Until I Learned THESE 5 Things!
7:40
Pooja Dutt
Рет қаралды 1 МЛН
Reversing a String | JAVA INTERVIEW QUESTIONS
7:13
CYDEO
Рет қаралды 3,4 М.
Java Program to Reverse each Word of a String
5:49
Programming Tutorials
Рет қаралды 86 М.
Java Program #21 - Sort Numbers using Bubble Sort in Java
8:03
Programming For Beginners
Рет қаралды 37 М.
Reverse Sentence By Words - Logic Building Practice
6:49
CloudTech
Рет қаралды 21 М.
Palindrome Program In Java Tutorial #63
9:50
Alex Lee
Рет қаралды 101 М.