Ressourcenleck: „sc“ wird nie geschlossen

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Ressourcenleck: „sc“ wird nie geschlossen

by Guest » 05 Jan 2025, 13:45

Programm zum Zählen, wie oft ein bestimmtes Zeichen, ein bestimmter Buchstabe oder eine bestimmte Zahl in einem Satz vorkommt.

Allerdings erhalte ich immer wieder die Meldung:


Ressourcenleck: 'sc' is nie geschlossen


Ich verwende Java und Eclipse. Was soll ich tun?

Code: Select all

import java.util.Scanner;
class Number-count {
public static void number - count(String args[]) {
String s;
char ch;
int count = 0;
Scanner SC = new Scanner(System. in );
System.out.println("Enter a sentence");
String str = sc.nextLine();
System.out.println("Enter a character to be searched for occurence");
s = sc.nextLine();
char c = s.charAt(0);
for (int i = 0; i < str.length(); i++) {
ch = str.charAt(i);
if (ch == c) {
count++;
}
}
System.out.println("Character " + c + " occur " + count + " times");
}
}

Top