I can't find an error in the Java code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HarrySto
    New Member
    • Nov 2022
    • 10

    I can't find an error in the Java code

    I wrote the source code for a new application on IOS, when writing there were no errors, but when I ran the code, an error appeared in this place:
    Code:
    var t = readLine()!
    var s = readLine()!
    var len_s = s.count
    var t_lis = Set(t)
    var c_s   = Counter(s)
    var c_t   = Counter(t_lis[len_s])
    var c_res = [String: String]()
    var summ  = 0
    for e in c_s{
        c_res[e] = [c_s[e], min( c_s[e], c_t[e] )]
        summ += c_res[e][1]}
    for i in (t.count-s.count) + 1 {
        if summ == len_s-1{
            print(i)
            break
            
        }
        if t[i] in c_res
                if c_res[t[i]][1] > 0{
                c_res[t[i]][1] -= 1
                summ -= 1
        }
        if i+len_s < t.count && t[i+len_s] in c_res
            if c_res[ t[i+len_s] ][1] < c_res[ t[i+len_s] ][0]{
                c_res[ t[i+len_s] ][1] += 1
                summ += 1
            
        }
        else
        print(-1)
            }
    Who can tell what is wrong?
    And does anyone know a quality service for code analysis? Which could make one code unique across multiple projects. Thanks in advance!
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 656

    #2
    I wrote the source code for a new application on IOS, when writing there were no errors, but when I ran the code, an error appeared in this place:
    What error? ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎

    Comment

    • HarrySto
      New Member
      • Nov 2022
      • 10

      #3
      Originally posted by dev7060
      What error? ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎
      The whole part of this code does not work and is highlighted in red, the description of the error is missing

      Comment

      • dev7060
        Recognized Expert Contributor
        • Mar 2017
        • 656

        #4
        The whole part of this code does not work and is highlighted in red, the description of the error is missing
        How do you know the posted code is in Java language? What is the version of JDK? What is the code about? What is highlighted where? What are you doing? What is the environment?

        Comment

        • Alpha Teng
          New Member
          • Jun 2023
          • 1

          #5
          This is not Java code!

          Comment

          Working...