-4

package com.company;

import java.util.*;

    public class Main {
        public static void main(String[] args) {
            String s="1239586838923173478943890234092";
            for(int i=0;i<10;i++) {
                int count=0;
                int k=-1;
                while(s.indexOf(i+"",k+1)!=-1){
                    k=s.indexOf(i+"",k+1);
                    count++;
                }
                System.out.println(i+"出现的次数是"+count);
            }
        }
    }

Here,

indexOf(i+"",k+1)

i+"" ? why? what's means?

Pushpesh Kumar Rajwanshi
  • 18,127
  • 2
  • 19
  • 36

3 Answers3

1

That's because String.indexOf accepts the argument of type String and int.

The code in your block as

i + ""

is used to convert the number of type int into a String.

Naman
  • 27,789
  • 26
  • 218
  • 353
0

i + "" is one way of converting an int into a String.

Joe C
  • 15,324
  • 8
  • 38
  • 50
0

This is a (very ugly) way to convert an int into a String.

See How do I convert from int to String? for better ways.

Dorian Gray
  • 2,913
  • 1
  • 9
  • 25