By GokiSoft.com|
16:15 12/06/2023|
Java Basic
Java Basic- In chuỗi ngược String in java
Viết chương trình nhập vào 1 chuỗi str
In ra thứ tự ngược lại của chuối (ví dụ : str là "xin chao" thì in ra dòng : oahc nix)
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)
Nguyen Tri Duc
2023-04-18 10:06:48
public class InStrNguoc {
public static void main(String[] args) {
String str = "xin chao";
String reverse = "";
for(int i = str.length()-1; i >= 0; i--) {
reverse = reverse + str.charAt(i);
}
System.out.println(reverse);
}
}
le anh tuan
2022-09-06 08:08:26
package fibonaci;
import java.util.Scanner;
/**
*
* @author Skynet
*/
public class String_nguoc {
public static void string_nguoc(){
Scanner input = new Scanner(System.in);
System.out.print("Nhap vao chuoi ki tu: ");
String str = input.nextLine();
StringBuilder reverseString = new StringBuilder(str);
reverseString.reverse();
System.out.println("chuoi dao nguoc la: "+ reverseString);
}
public static void main(String[] args){
string_nguoc();
}
}
Nguyễn Viết Nguyên
2022-07-13 11:07:37
import java.util.Scanner;
public class ReverseString {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a string: ");
String text = scanner.nextLine();
System.out.println("Reverse string by for loop:");
// use for loop
for (int i = text.length()-1;i >= 0;i--){
System.out.print(text.charAt(i));
}
// use while loop
System.out.println("\nReverse string by while loop:");
int index = text.length()-1;
while (index>=0){
System.out.print(text.charAt(index));
index--;
}
// use do while loop
System.out.println("\nReverse string by do while loop:");
int index2 = text.length()-1;
do {
System.out.print(text.charAt(index2));
index2--;
}while (index2>=0);
}
}
Hoàng Anh
2022-06-27 13:27:04
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication1;
import java.util.Scanner;
/**
*
* @author by bom1
*/
public class baitap983 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("nhập vào chuỗi string:");
String str = input.nextLine();
StringBuilder reversestring = new StringBuilder(str);
reversestring.reverse();
System.out.println("Chuỗi bình thường: " + str);
System.out.println("Chuỗi ngược lại: " + reversestring);
}
}
Minh Nghia
2020-03-19 06:51:17
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package aptech;
import java.util.Scanner;
/**
*
* @author Administrator
*/
public class Bt138 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String str ;
str = scan.nextLine();
System.out.println("Nhap chuoi:" + str);
String a = new StringBuffer(str).reverse().toString();
System.out.println("Hien thi chuoi dao nguoc:" + a);
}
}
Trần Mạnh Dũng
2020-03-16 13:17:21
package bt138;
import java.util.Scanner;
public class BT138 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Nhập 1 chuỗi bất kì: ");
String str = scan.nextLine();
for (int i = str.length() - 1; i >= 0; i--) {
System.out.print(str.charAt(i));
}
System.out.println("");
}
}
Lê Minh Bắc
2020-03-16 12:29:52
package bt138;
import java.util.Scanner;
public class BT138 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Nhập 1 chuỗi bất kì: ");
String str = scan.nextLine();
for (int i = str.length() - 1; i >= 0; i--) {
System.out.print(str.charAt(i));
}
System.out.println("");
}
}