public class Schleifen{
public static void main(String[] args) {
int a = 1, b = 1;
System.out.println();
while (a < 10)
{
System.out.println("Schleifendurchlauf " + a);
if (a == 9) System.out.println();
a++;
}
do
{
System.out.println("Schleifendurchlauf " + b);
if (b == 9) System.out.println();
b++;
}
while (b < 10);
for (int c = 1, d = 19, jahr = 2013; c < d; c++, d--)
{
System.out.print("Schleifendurchlauf " + c + " im Jahr " + jahr + ".");
System.out.println(" c = " + c + ", d = " + d);
}
}
}
Scanner sc = new Scanner(System.in);
while(sc.hasNext()) {
String next = sc.next();
System.out.println(next);
if (next.matches("\\d+(\\.\\d+)?")) {
System.out.println("Zahl!");
}
if (next.contentEquals("ende")) {
System.out.println("Ende Gelände");
break;
}
}
//mit Rechnung und return
Scanner sc = new Scanner(System.in);
Double res = 0.0;
while(sc.hasNext()) {
String next = sc.next();
System.out.println(next);
if (next.matches("\\d+(\\.\\d+)?")) {
System.out.println("Zahl!");
res = res + Double.parseDouble(next);
}
if (next.contentEquals("ende")) {
System.out.println("Ende Gelände: " + res);
break;
}
}
return res;
More evil Regex