Frequently Asked Java Program 02: Reverse A Number | 3 Ways of Reverse a Number
Vložit
- čas přidán 7. 09. 2024
- Topic: Reverse a Number ( 3 Different ways)
#########################
Udemy Courses:
#########################
Manual Testing+Agile with Jira Tool
************************************
► shorturl.at/xNXZ4
Selenium with Java+Cucumber
********************************
► shorturl.at/aIKMW
Selenium with Python & PyTest
********************************
► shorturl.at/ELW09
Selenium with python using Robot framework
****************************************
► shorturl.at/bcDPZ
API Testing(Postman, RestAssured & SoapUI)
*****************************************
► shorturl.at/uAWY7
Web & API Automation using Cypress with Javascript
********************************************
► rb.gy/4uum2n
Playwright with Javascript
**************************
► shorturl.at/gALZ1
Jmeter-Performance Testing
************************
► rb.gy/ocj7r2
SDET Essencials(Full Stack QA)
*************************
► rb.gy/hlnf2v
Appium-Mobile Automation Testing
************************************
► rb.gy/wmzv64
Java Collections
*****************
► bit.ly/3S66ezE
Python Programming
*********************
► urlis.net/gdsf...
Cucumber BDD Framework
***************************
► bit.ly/3F7d69r
Protractor with Javascript
***************************
► urlis.net/4udd...
####################################
CZcams Playlists:
####################################
Manual Testing & Agile
***********************
► bit.ly/3ujvaYa
► bit.ly/3OYzxQj
SQL
*************************
► bit.ly/3R6XjeG
► bit.ly/3nE0a1s
► bit.ly/3IeKuuJ
linux & Shell Scripting
**********************
► bit.ly/3up1Z6a
► bit.ly/3nzvGxx
Java
**********************
► bit.ly/3R9QfOs
► bit.ly/3AoRMKM
► bit.ly/3IbTTDn
► bit.ly/3ybXInv
► bit.ly/3yCoHdw
Selenium With Java+Cucumber
********************************
► bit.ly/3P2FMm4
► bit.ly/3yhiIt4
► bit.ly/3uokzet
► bit.ly/3a7XIND
► bit.ly/3umN2S9
► bit.ly/3aar7GW
► bit.ly/3y9kD2S
► bit.ly/3uhLskn
Python
********************************
► bit.ly/3agNgU0
► bit.ly/3NJNnoy
► bit.ly/2CTQ4mR
► bit.ly/3OIYWh1
Selenium With Python,Pytest&Behave
***************************************
► bit.ly/3OHHoC9
► bit.ly/3IeNLdv
► bit.ly/2J4tPeT
► bit.ly/3ydSkAq
Selenium With Python Using Robert Framework
(Web&API Testing)
*************************************************
► bit.ly/3nUvlpr
► bit.ly/3nUvE3z
API Testing (Postman,SoapUi,&Rest Assured)
**********************************************
► bit.ly/3OXacWY
► bit.ly/3yh0UhE
► bit.ly/3nC9DWQ
► bit.ly/3yGfhNS
► bit.ly/3OJa11H
► bit.ly/3P2slCC
Mobile App Testing Appium
****************************
► bit.ly/3Al49HG
Performance Testing Jmeter
*******************************
► bit.ly/3nz4fE7
Maven,Jenkins,Git,Github,CI/CD
*******************************
► bit.ly/3P16HPj
► bit.ly/3yhlUVA
► bit.ly/3afYfwT
► bit.ly/3yGzweG
► bit.ly/3yF73Ws
► bit.ly/3NCOmH7
SQL,DB Testing&ETL,Bigdata
*******************************
► bit.ly/3NKOcNY
► bit.ly/3OVpDyI
► bit.ly/3NEvUy0
► bit.ly/3IryxlT
► bit.ly/3RkWBLh
JavaScript Based Automation Tools
********************************
► bit.ly/3nUx51X
► bit.ly/3AqI6Q0
► bit.ly/3yeurbT
► bit.ly/3ujzpTK
Selector Hub Tools
********************
►rb.gy/h3h424
GraphQL
******************
► rb.gy/sj3gys
Cypress API Testing
********************
► shorturl.at/fjKPX
Cypress Web Testing
**********************
► shorturl.at/agjlK
Playwright with Javascipt
**************************
► shorturl.at/adSTY
#JavaNumberReversal
#ReverseNumber
#JavaProgramming
#CodeReversal
#JavaTips
#NumberManipulation
#ProgrammingHelp
#JavaBeginner
#CodingChallenge
#Java101
#CodingCommunity
#LearnJava
#JavaTricks
#CodeSnippets
#ReverseInteger
#JavaDevelopment
#ProgrammingQuestions
#Algorithm
#JavaAlgorithms
#CodingProblems
#CodingSolutions
#TechInterview
#CodingSkills
#JavaHelp
#ReverseDigits
#JavaLearning
#ProgrammingLogic
#JavaProblems
#JavaCode
#CodeExamples
#ReverseAlgorithm
#JavaCommunity
#CodingTutorials
#ReverseNumberLogic
#JavaChallenge
#SoftwareDevelopment
#ProblemSolving
#ProgrammingLanguages
#JavaCodeSnippet
#ReverseNumberFunction
#JavaPuzzle
#ProgrammingJourney
#JavaCoders
#JavaPractice
#CodeReview
#AlgorithmDesign
#JavaMentorship
#JavaDev
#ProgrammingProblems
#JavaCodingTips
Who are here in 2024!
2 Years later and this video explained perfectly to assist me with my AP CS Class. Thanks man.
Welcome
Everything is awesome...
just a small correction:
% : This is called remainder operator, which gives the remainder as output.
as in 123%10 gives 3 as remainder.
and
/ : this is division operator and gives the value after division.
as in 123/10 gives 12.3 as answer but if you have taken it as int then it will give 12.
It divides left-hand operand by right-hand operand and returns remainder and is called as (Modulus) not remainder operator
Thanks, I was confused and watched the video 2 times and then read this comment. Now got cleared...
The creator is using a strategy to increase watch time.
@@madhavkiagya No, the creator is doing a great job. You need to brush up you basics.
@@ibbishariff yes, thanks...
I liked here StringBuilder option the most. For 12300 it returns us 00321 but Option1 - Modulus one returns just 321 which is not good. Also, for numbers more than 9-10 digits Option 1 doesn't work but StringBuffer and StringBuilder comes over well . Thanks for the video !
czcams.com/users/shortsH2z9YYe0Yvw?feature=share
Excellent explanation. Even a nontechnical guy like me can comprehend easily. Thanks a lot, sir
You are most welcome
Thank you for explaining in very easy manner
Glad it was helpful!
I always wanted these logics.Guess i found the right channel .Thanks a ton sir!
You are best teacher in the world ,yours teaching skills is awesome sir
Thanks
Thanks sir.. logic explanation is really simple .. I’m referring your videos for interviews and it really helping me ..
But sir , number enter to 1230 this no not reverse 0321 .. Output is 321 so 0 is eliminate so plz suggest logic for last digit 0
Use stringBuffer or stringBuilder methods
Int num = 12340;
int rev = 0 ;
While(num!=0) {
rev = (rev*10) + num%10;
num/=10;
}
System.out.println(rev);
Try this 👍
@@shankardeepak-pr9blStil removes the zero (:
@@shankardeepak-pr9bl not worked
Use while(num>=0)
Hello , I think 2nd and 3rd methods are same. I think 3rd one can be like converting number to string and then using charAt method to extract each char and then appending to the sting builder
int origNum = 123456;
String stNum = String.valueOf(k);
StringBuilder revStg = new StringBuilder();
for (int i = stNum.length()-1; i>=0;i--)
{
revStg.append(stNum.charAt(i));
}
System.out.println(revStg);
}
}
My exams are nearing and I found this video. This is so useful. Thank you sir
You are most welcome
You explained programming very well, easy to understand.. Thank you sir
You are most welcome
Great thanks you sir ☺. You are simply awesome.. coding med interest leni naaku, meerichhe explanation tho interest vachhestundi.. I am practcing well. Once again Thank you very much sir 🙏
Welcome
int reversed = 0;
while (num != 0) {
int digit = num % 10; // Extract the last digit
reversed = reversed * 10 + digit; // Append digit to reversed number
num /= 10; // Remove the last digit from original number
}
package reversestring;
import java.util.Scanner;
public class ReverseString {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the sentence::");
String stnce=sc.nextLine();
System.out.println(new StringBuilder(stnce).reverse());
}
}
Splendid explaination sir 💯
Thanks
You explain it the best way thanks a lot sir...
Welcome
i think we can also reverse integer or string by using FOR loops ...
Thank you, I was looking for such series in hindi.
Thank you again
Welcome
Respected sir please help
I came in this video from your Udemy course selenium with java+ cucumber...
I watched your video until 6(conditional statement & looping statement) and i came here for assignment...i watched your video but here I couldn't understand idk sir plz help me...and try to re upload your video...and why you didn't solve assignment in udamy😥😢
Such a good explanation , Sir 😊
Thanks
WOWWWW.... FINALLY!!!!! Well explained. Great teaching. THANK YOU
welcome
Why rev×10?
Hi Bro, There is one more way
public static String reverseNum(int num) {
String reverseString = "";
String str = Integer.toString(num);
char[] chr = str.toCharArray();
for (int i = 1; i
will it work -123?
your explain is very clear ,it ease to understand
Thanks
Sir, first method won't work if we try to reverse *'00111'* right as we will get *37* as output.
static int reverseNumber(int num) {
int rev = 0;
while (num != 0) {
rev = rev * 10 + num % 10;
num /= 10;
}
return rev;
}
System.out.println(reverseNumber(00111));
Output = 37
I think the input taken sc.nextInt can result in exception if user enters non number or mixed input... we should handle it in a better way
Very Nice Explaination...Thank You Sir...!!!
You are most welcome
Explanation is excellent but,the xor u said that is not correct it would be bidirectional then if the values are same its 1 otherwise its 0
without using string buffer and builder
import java.util.Scanner;
public class Main
{
public String reverse(String sc){
String rev= "";
for(int i=sc.length()-1; i>=0;i--){
rev = rev +sc.charAt(i);
System.out.println("rev string "+rev);
}
return rev;
}
public static void main(String[] args) {
Scanner p = new Scanner(System.in);
System.out.println("enter a number: ");
String sc = p.next();
Main obj = new Main();
obj.reverse(sc);
}
}
Sir If we give input as 67890 then 0 is being ignored and output displaying 9876..What logic can we add in order to not ignore zero as well?
Thank you so much ❤did this for my assignment
Welcome
This one was super cool
Thanks
System.out.println("Logic_3");
System.out.println("Enter Number");
Scanner sc=new Scanner(System.in);
int num=sc.nextInt();
StringBuilder rev;
//Using String Builder Class
StringBuilder sbl=new StringBuilder(String.valueOf(num));
rev=sbl.reverse();
System.out.println("Reverse number is" + rev); This logic also workng for third logic
Why need to append when using string builder? it also has inbuilt reverse method...so why not use it directly....only that logic i didn't get...somebody please...
thank you sir for this explanation it is really helpful ,i have doubt if we dont use scanner class is there any mistakes
Thank you so much sir 🎉
Great explanation ❤
Most welcome
Thank you so much sir for providing very useful videos for free.
Welcome
Very neat and clean explanation sir.....keep up👏
czcams.com/users/shortsH2z9YYe0Yvw?feature=share
Thanks
thank you ,please upload more java programs...
See more here:czcams.com/video/BfAJkKDHTQk/video.html
Super sir grear teaching
Thanks
When there is easy methods string buffer and builder they why to go for algorithm ?
Perfect Explanation ❤️🙌🏻
Glad it was helpful!
Thank you so much very clear explanation
You’re welcome
Thank u sir
Welcome
How to identify that logic sir rev=(rev*10)+num/10
can we do that using a string concat
tq sir please make more on aptitude we are waiting for ur classess anna
oh wow you are superb the way of explanation great sir
am preparing for gsoc wish it help me
czcams.com/users/shortsH2z9YYe0Yvw?feature=share
What about reversing a number like 67890 with the algorithm mentioned here? It will not consider 0 and will only print 9876.
we can u the recursion method, try this :)
import java.util.Scanner;
public class ReverseNumberExample3
{
//method for reverse a number
public static void reverseNumber(int number)
{
if (number < 10)
{
//prints the same number if the number is less than 10
System.out.println(number);
return;
}
else
{
System.out.print(number % 10);
reverseNumber(number/10);
}
}
public static void main(String args[])
{
System.out.print("Enter the number that you want to reverse: ");
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
System.out.print("The reverse of the given number is: ");
//method calling
reverseNumber(num);
}
}
Amazing 🎉
thanks
Sir can we revers float and double values by using string buffer and string builder
Excellent sir🤗
Thanks
How come when I use the same endpoints you're using my program isn't as reactive as yours. In other words as I hover over "rev" I should see 4 and then 43 etc.
That logic got failed if you give a number at last "0" like 890
output: 98 only
nobody is going to reply to this because no one knows
😆😆
@@rijo_tthomas3785 🤣
no bro its working fine.
Yeah I tried With 120 it is giving reverse O/P as
21
Thank you very much sir make more videos related to strings and arrays also
Best explanation ever.
Thanks
for the first approach, it won't work with 230 or no module number. for 230 it will show 32 how can we achieve 032 that with the first method
import java.util.Scanner;
public class ReverseNumber {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
String num=sc.next();
Integer num2 = Integer.parseInt(num);
int count = 0;
int count2 = 0;
char[] s = num.toCharArray();
for (char s1 : s) {
if(!String.valueOf(s1).equals("0")){
break;
}else {
count++;
}
}
for(int k=s.length; k > 0; k--) {
if(!String.valueOf(s[k-1]).equals("0")) {
break;
}else {
count2++;
}
}
//using algorithm
int rev=0;
while(num2!=0)
{
rev=rev*10 + num2%10;
num2=num2/10;
}
int i = 0;
String reverse = String.valueOf(rev);
if(rev == 0) {
reverse = "";
}
while(i
Sir , If i have enetered 121820, with 1st method its showing as 28121, ideally it should be 028121, its stripping the zero here
please suggest!
Excellent man
Thanks
Thanks you please upload for beginners
Welcome
Thank you sir 🙏
Sir direct aisa likh sakhte hai kya??...
Example 1234 ko reverse Karo bole
Aur apan ne aisa direct likha toh??
public class Main {
public static void main(String[] args) {
int rev=4321;
System.out.println("Reverse number is " + rev);
}
}
Aisa karke output 4321 aah raha
Hi Sir , Can you please explain how 1234/10 will be 123
Is it beacuse we are eliminating the decimal value because we have passed the variable has int =1234
Try this
public class Reverse {
public static void main(String[] args) {
int num = 12635;
String rev = "";
int rem = 0;
while(num>=1){
rem = num%10;
rev = rev + rem;
num = num/10;
}
System.out.println(rev);
}
}
Thank you so much.
Welcome
Thanks so much for this
You are so welcome!
please collection videos need for interview
perfect job
i love you bro, May The Lord of all bless you
Super
thanks
how to enable explanation steps in eclipse sir
% is not divided by operator.
love u sir
what if the last digit is 0, eg: 120 (I'm getting a wrong answer when the user enter an integer ends with 0)
found the solution, thanks anyways
Sir what is the use of append method sir??
Owasome
Thanks
Sir your StringBuffer approach is wrong as the the output will be a string type not an int type to convert this to int type you need to use below code
String s = rev.toString();
int i = Integer.parseInt(s);
System.out.println(i);
Thank you
Well explained
Thanks
Screen isn't visible clear
how do you add space in the middle
thank you very much
Welcome
Sir can u please explain about append()
i have written like this, is this correct way to write the code.
int i= 1234;
while(i!=0) {
System.out.print(i%10);
i=i/10;
}
01234 please tell us how to write program
Thanks for your all videos. Can you make some video for DataStructure and Algorithm
Sir which editor are you using
Wow
Thanks
sir can you take mock interview??? we will pay for that. plz reply
I take free mock interviews. You can send your profile to my email ID. I will schedule an interview.
@@sdetpavan thank you so much
sir mobileNumber how to Write reverse
Sir is the below approach valid
Int num = 1234;
While(num!=0)
{
Int n = num%10;
num = num/10;
System.out.print(n);
}
Right
@@sdetpavan
Thanks for the reply sir
first approach is totally wrong and shouldnt be in practice , try reversing 100 using this approach , it will give only 1.which is not reverse.instead take a string input and use reverse string approach to reverse a number.Just for the time.
some noise sound is coming sir its annoying disturbing ur teaching and me also
but 10 20 50 can't be reverse.. because the result is 05 02 01
how the solution that problem sir.. thanks
Hello
Nageswara rao sir student😂
Hi, thanks for your videos
Could you please check this
import java.util.Scanner;
public class ReverseNumber {
public static void main(String[] args) {
System.out.println("Please enter the number");
Scanner sc = new Scanner(System.in);
String input = sc.nextLine();
System.out.println("User entered "+ input);
//Method 1
StringBuffer sb = new StringBuffer(input);
System.out.println("Reverse number is " +sb.reverse());
//Method2
StringBuilder sbi = new StringBuilder(input);
System.out.println("Reverse number is " +sbi.reverse());
}
}
Thank you!
You're welcome!