-5

I changed String to char[] i want to delete where char[i] = n, i can do it when i print temp[i]. but I need to get print temp[i] to String again. Here my code

 public String missingChar(String str, int n){

    char[] temp = str.toCharArray();
    String hasil = new String(temp);
    for (int i= 0; i<temp.length; i++){
        if(i!=n){

            System.out.print(temp[i]);

        } 

    }
    return "I don't know how to get String from System.out.print(temp[i]);";
}

}

  • 1
    Use a StringBuilder in your loop instead of printing each single char. – Tom Aug 05 '16 at 11:21
  • I am not sure what you are trying to accomplish. Could you post some example of input and expected result with little explanation about why it should be expected? – Pshemo Aug 05 '16 at 11:22
  • example :missingChar("name, 0) then the result is "ame" – Rijen Juni Aug 05 '16 at 11:26
  • Create instance of `StringBulder` and `append` each character you want to it. Then call `toStrng()` method on it to get its content as String. – Pshemo Aug 05 '16 at 11:28
  • You can not get anything back from `System.out.print`. The printed text is one-way printed to outside of your application. – zapl Aug 05 '16 at 11:33

1 Answers1

-3

Build a StringBuffer containing the result and Use String.format to get a string from a formatted output

baliman
  • 588
  • 2
  • 8
  • 27