package t02;
import java.util.Scanner;
public class XExercise01 {
public static void main(String[] args) {
double r, s;
final double PI = 3.14;
Scanner sc = new Scanner(System.in);
System.out.print("r = ");
r = sc.nextDouble();
if (r < 0) {
System.out.println("温馨提示:半径不能为负!");
return;
}
s = PI * r * r;
System.out.println("s = " + s);
}
}
利用结构防范用户输入负的半径
*单分支结构一般用于把关和过滤。当然大家可以用双分支解决这个问题。
package t02;
public class XDemo01 {
public static void main(String[] args) {
for(int i = 1; i <= 100; i++) {
if(i % 3 == 0 || i % 5 ==0){
System.out.print(i + “t”);
}
}
}
}



