how to reverse a string in java | Ways of reversing a String in java | Solution

Publié le: 10 novembre 2022
sur la chaîne: human compiler
7
0

how to reverse a string in java | Ways of reversing a String in java | Solution
In this video i am writing program of reversing a string in java. There are many ways to reverse a string in java.
package com;


// First way of reversing a string in java (Using String Buffer)

/***public class reverse {

public static void main(String[] args) {
// TODO Auto-generated method stub

StringBuffer r=new StringBuffer("Human Compiler");
System.out.println(r.reverse());

}

}

//Second way of reversing a string in java (Using String Builder)
public class reverse {

public static void main(String[] args) {
// TODO Auto-generated method stub

StringBuilder r=new StringBuilder("Human Compiler");
System.out.println(r.reverse());

}

}
***/

//Third way of reversing a string in java

public class reverse {

public static void main(String[] args) {
// TODO Auto-generated method stub

String s1="";
String str="human";
int s=str.length();

for(int i=s-1;i=0;i--) { (Angle bracket missed here..)
s1=s1+str.charAt(i);
}
System.out.println(s1);

}

}

This is the code. you can just copy from here and paste it in your editor.


Sur cette page du site, vous pouvez voir la vidéo en ligne how to reverse a string in java | Ways of reversing a String in java | Solution durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur human compiler 10 novembre 2022, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 7 fois et il a aimé 0 téléspectateurs. Bon visionnage!