Is it permissible to perform the% module operation with double number in java, and how to change a unique position of a string in java? [closed]

-3

My doubts ..

  • Is it permissible to perform the floating-point number% module operation in java, and why? Because in compilers such as c ++ this operation is not allowed.

  • How do I access an element of a string and change it? Example, I have a string. String s="wave"; How to change the 0 position of the element by a letter the carousel?

  • Is it allowed to access a String as an array? example str [i].

asked by anonymous 01.08.2018 / 22:22

1 answer

2

1:

class Teste {
    public static void main(String[] args) {
        System.out.println(6.25 % 2.5);
    }
}

Output: 1.25.

2: String s are immutable! That is, you would have to create a new String instead of changing the existing one. For example:

String s = "ola";
String s2 = "x" + s.substring(1);
System.out.println(s2);

The output is xla .

3: No. But you can do something like this:

String s = "teste";
char[] array = s.toCharArray();
array[2] = 'x';
String s2 = new String(array);
    
01.08.2018 / 22:32