1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
|
public class Zählen
{
public static void main (String[]args)
{
System.out.println(zähle5en (252525));
}
public static int zähle5en (int zahl)
{
Integer meinInteger = new Integer(zahl);
String s = meinInteger.toString();
int counter = 0;
for (int i=0;i<s.length()-1;i++)
{
if (s.charAt(i)==5)
{
++counter;
}
}
return counter;
}
}
|