This question has already been answered:

It is necessary to separate the numbers with a space to determine what type of number is being entered and what operation (+ - * /).

But for some reason the split point does not think so .... How to fix? And how to determine str.charAt (i) == what type?

str="3.5 + 2"; str.split(" "); for(int i=0; i < str.length(); i++) { System.out.println(str.charAt(i)); } 

Reported as a duplicate by members arg , Deadkenny , Athari , Yura Ivanov , VenZell Apr 4 '15 at 5:07 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    2 answers 2

    Strings in Java are immutable objects. if you think that str.split(" "); divided the string then no, I will disappoint you.

    String[] result=str.split(...); that's how it should be. It is necessary to refer to the element of the array. And in general, it is a duplicate. here you are for details. learn to use search before asking a question

    • String tmp []; tmp = str.split ("\\ u0020"); for (int i = 0; i <tmp.length; i ++) System.out.println ("TMP =" + tmp [i]); - Stein_
    • In general, thank you figured out at the same time as you wrote - Stein_
    • Please tell me ... float peremf; if (tmp [i] .indexOf (".") == 1) {peremf = tmp [i]; } How to take a value in a string and assign it to a variable with a dot ??? @argamidon - Stein_

    Of course, I don’t shave Java and have never programmed. But I think you have an erroneous call to the array. You split the str command with an array by specifying a space character. Split returns an array, and you are not accessing an array element, but a symbol. What if you make an appeal:

     System.out.println(str(i)) 
    • But how then to turn to the divided part? ... - Stein_