System.in : System « java.lang « Java by API






System.in

    
/*
 * Output:
 */

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class MainClass {

  public static void main(String args[]) {
    try {

      InputStreamReader isr = new InputStreamReader(System.in);
      BufferedReader br = new BufferedReader(isr);

      while (true) {

        System.out.print("Radius? ");

        String str = br.readLine();
        double radius;
        try {
          radius = Double.valueOf(str).doubleValue();
        } catch (NumberFormatException nfe) {
          System.out.println("Incorrect format!");
          continue;
        }

        if (radius <= 0) {
          System.out.println("Radius must be positive!");
          continue;
        }

        double area = Math.PI * radius * radius;
        System.out.println("Area is " + area);
        return;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

           
         
    
    
    
  








Related examples in the same category

1.System.exit(int status)
2.System.in.read()
3.System.out
4.System: arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
5.System: clearProperty(String key)
6.System: console()
7.System: currentTimeMillis()
8.System: getenv(String key)
9.System: getProperty(String name)
10.System.getProperty ("user.dir")
11.System: getProperty(String key, String def)
12.System: getProperties()
13.System.identityHashCode(Object x)
14.System: nanoTime()
15.System.setErr(PrintStream err)
16.System: setIn(InputStream in)
17.System: setOut(PrintStream err)
18.System: setProperty(String key, String value)