Eclipse isnt recognizing StringBuilder for some reason. This program just prompts for user and nothing afterwards. This code has no compilation errors. Does anyone know a reason this may be happening?
ex. of output:
Enter a string:
enter new string
import java.util.*;
public class StringBuilder001{
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s = new Scanner(System.in);
StringBuilder sb = new StringBuilder();
System.out.println("Enter a string:\t");
String input = s.nextLine();
String[] arr = input.split(input);
for (int i = arr.length-1; i>=0 ; i--)
sb.append(arr[i]);
System.out.println(sb);
The bug is in the
String[] arr = input.split(input);
It should be ( or some other split char)
String[] arr = input.split(" ");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.