我想使用while循环,因此它可以捕获任何无效的输入,如字母或随机%% $ @@等等如何添加或在我的代码中使用While循环
Im new to java ......对于很多球员乌尔THANKS帮助:) 这里是林工作:
import java.util.Scanner;
public class AreaCircle {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in); // read the keyboard
System.out.println("This program will calculate the area of a circle");
System.out.println("Enter radius:");//Print to screen
double r = sc.nextDouble(); // Read in the double from the keyboard
double area = (3.14 *r * r);
String output = "Radius: " + r + "\n";
output = output + "Area: " + area + "\n";
System.out.println("The area of the circle is " + area);
}
}
至少告诉我们你试过使用while循环。堆栈溢出不是代码工厂 – 2012-03-17 16:49:13
您应该尝试谷歌它,看这里: http://www.java2s.com/Code/Java/Development-Class/Howtoreadfromstandardinput.htm – 2012-03-17 16:49:45