Example usage for java.lang System in

List of usage examples for java.lang System in

Introduction

In this page you can find the example usage for java.lang System in.

Prototype

InputStream in

To view the source code for java.lang System in.

Click Source Link

Document

The "standard" input stream.

Usage

From source file:math2605.gn_log.java

/**
 * @param args the command line arguments
 *///from w ww.ja  v a 2s  .co m
public static void main(String[] args) {
    //get file name
    System.out.println("Please enter a file name:");
    Scanner scanner = new Scanner(System.in);
    String fileName = scanner.nextLine();
    List<String[]> pairs = new ArrayList<>();
    //get coordinate pairs and add to arraylist
    try {
        BufferedReader br = new BufferedReader(new FileReader(fileName));
        String line;
        while ((line = br.readLine()) != null) {
            String[] pair = line.split(",");
            pairs.add(pair);
        }
        br.close();
    } catch (Exception e) {
    }

    System.out.println("Please enter the value of a:");
    double a = scanner.nextInt();
    System.out.println("Please enter the value of b:");
    double b = scanner.nextInt();
    System.out.println("Please enter the value of c:");
    double c = scanner.nextInt();
    //init B, vector with 3 coordinates
    RealMatrix B = new Array2DRowRealMatrix(3, 1);
    B.setEntry(0, 0, a);
    B.setEntry(1, 0, b);
    B.setEntry(2, 0, c);

    System.out.println("Please enter the number of iteration for the Gauss-newton:");
    //init N, number of iterations
    int N = scanner.nextInt();

    //init r, vector of residuals
    RealMatrix r = new Array2DRowRealMatrix();
    setR(pairs, a, b, c, r);

    //init J, Jacobian of r
    RealMatrix J = new Array2DRowRealMatrix();
    setJ(pairs, a, b, c, r, J);

    System.out.println("J");
    System.out.println(J);
    System.out.println("r");
    System.out.println(r);

    RealMatrix sub = findQR(J, r);

    for (int i = N; i > 0; i--) {
        B = B.subtract(sub);
        double B0 = B.getEntry(0, 0);
        double B1 = B.getEntry(1, 0);
        double B2 = B.getEntry(2, 0);
        //CHANGE ABC TO USE B0, B1, B2
        setR(pairs, B0, B1, B2, r);
        setJ(pairs, B0, B1, B2, r, J);
    }
    System.out.println("B");
    System.out.println(B.toString());
}

From source file:math2605.gn_exp.java

/**
 * @param args the command line arguments
 *//*from  w  w w.  j  av  a 2s. co  m*/
public static void main(String[] args) {
    //get file name
    System.out.println("Please enter a file name:");
    Scanner scanner = new Scanner(System.in);
    String fileName = scanner.nextLine();
    List<String[]> pairs = new ArrayList<>();
    //get coordinate pairs and add to arraylist
    try {
        BufferedReader br = new BufferedReader(new FileReader(fileName));
        String line;
        while ((line = br.readLine()) != null) {
            String[] pair = line.split(",");
            pairs.add(pair);
        }
        br.close();
    } catch (Exception e) {
    }

    System.out.println("Please enter the value of a:");
    double a = scanner.nextInt();
    System.out.println("Please enter the value of b:");
    double b = scanner.nextInt();
    System.out.println("Please enter the value of c:");
    double c = scanner.nextInt();
    //init B, vector with 3 coordinates
    RealMatrix B = new Array2DRowRealMatrix(3, 1);
    B.setEntry(0, 0, a);
    B.setEntry(1, 0, b);
    B.setEntry(2, 0, c);

    System.out.println("Please enter the number of iteration for the Gauss-newton:");
    //init N, number of iterations
    int N = scanner.nextInt();

    //init r, vector of residuals
    RealMatrix r = new Array2DRowRealMatrix();
    setR(pairs, a, b, c, r);

    //init J, Jacobian of r
    RealMatrix J = new Array2DRowRealMatrix();
    setJ(pairs, a, b, c, r, J);

    System.out.println("J");
    System.out.println(J);
    System.out.println("r");
    System.out.println(r);

    RealMatrix sub = findQR(J, r);

    for (int i = N; i > 0; i--) {
        B = B.subtract(sub);
        double B0 = B.getEntry(0, 0);
        double B1 = B.getEntry(1, 0);
        double B2 = B.getEntry(2, 0);
        //CHANGE ABC TO USE B0, B1, B2
        setR(pairs, B0, B1, B2, r);
        setJ(pairs, B0, B1, B2, r, J);
    }
    System.out.println("B");
    System.out.println(B.toString());

}

From source file:Redirecting.java

public static void main(String[] args) throws IOException {
    PrintStream console = System.out;
    BufferedInputStream in = new BufferedInputStream(new FileInputStream("Redirecting.java"));
    PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream("test.out")));
    System.setIn(in);//from w w w  .  ja v  a  2  s  . c  o m
    System.setOut(out);
    System.setErr(out);
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String s;
    while ((s = br.readLine()) != null)
        System.out.println(s);
    out.close(); // Remember this!
    System.setOut(console);
}

From source file:GetMessageExample.java

public static void main(String args[]) throws Exception {
    if (args.length != 3) {
        System.err.println("Usage: java MailExample host username password");
        System.exit(-1);/*ww  w .j  av  a 2 s . c o  m*/
    }

    String host = args[0];
    String username = args[1];
    String password = args[2];

    // Create empty properties
    Properties props = new Properties();

    // Get session
    Session session = Session.getDefaultInstance(props, null);

    // Get the store
    Store store = session.getStore("pop3");
    store.connect(host, username, password);

    // Get folder
    Folder folder = store.getFolder("INBOX");
    folder.open(Folder.READ_ONLY);

    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

    // Get directory
    Message message[] = folder.getMessages();
    for (int i = 0, n = message.length; i < n; i++) {
        System.out.println(i + ": " + message[i].getFrom()[0] + "\t" + message[i].getSubject());

        System.out.println("Read message? [YES to read/QUIT to end]");
        String line = reader.readLine();
        if ("YES".equalsIgnoreCase(line)) {
            System.out.println(message[i].getContent());
        } else if ("QUIT".equalsIgnoreCase(line)) {
            break;
        }
    }

    // Close connection
    folder.close(false);
    store.close();
}

From source file:divconq.hub.Daemon.java

public static void main(String[] args) {
    try {/*from   www  .  j  a va 2s  .  c  o m*/
        Daemon.startService(args);

        try (Scanner scan = new Scanner(System.in)) {
            System.out.println("Press enter to end Daemon");
            scan.nextLine();
        }
    } catch (Exception x) {

    }

    Daemon.stopService(args);
}

From source file:FactQuoter.java

public static void main(String[] args) throws IOException {
    // This is how we set things up to read lines of text from the user.
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    // Loop forever
    for (;;) {//from  w  w w. j  a v a  2  s  . c om
        // Display a prompt to the user
        System.out.print("FactQuoter> ");
        // Read a line from the user
        String line = in.readLine();
        // If we reach the end-of-file,
        // or if the user types "quit", then quit
        if ((line == null) || line.equals("quit"))
            break;
        // Try to parse the line, and compute and print the factorial
        try {
            int x = Integer.parseInt(line);
            System.out.println(x + "! = " + Factorial4.factorial(x));
        }
        // If anything goes wrong, display a generic error message
        catch (Exception e) {
            System.out.println("Invalid Input");
        }
    }
}

From source file:FlightInfo.java

public static void main(String args[]) {

    String to, from;/*  www .j a  va 2 s .  c  om*/
    Hill ob = new Hill();
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    ob.setup();

    try {
        System.out.print("From? ");
        from = br.readLine();
        System.out.print("To? ");
        to = br.readLine();

        ob.isflight(from, to);

        if (ob.btStack.size() != 0)
            ob.route(to);

    } catch (IOException exc) {
        System.out.println("Error on input.");
    }
}

From source file:Retirement.java

public static void main(String[] args) {
    // read inputs
    Scanner in = new Scanner(System.in);

    System.out.print("How much money do you need to retire? ");
    double goal = in.nextDouble();

    System.out.print("How much money will you contribute every year? ");
    double payment = in.nextDouble();

    System.out.print("Interest rate in %: ");
    double interestRate = in.nextDouble();

    double balance = 0;
    int years = 0;

    // update account balance while goal isn't reached
    while (balance < goal) {
        // add this year's payment and interest
        balance += payment;/*from ww  w  . ja va2 s. c om*/
        double interest = balance * interestRate / 100;
        balance += interest;
        years++;
    }

    System.out.println("You can retire in " + years + " years.");
}

From source file:com.github.liyp.dubbo.provider.Provider.java

public static void main(String[] args) throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            new String[] { "com/github/liyp/dubbo/provider/provider.xml" });
    context.start();/*www.  java  2  s .c  om*/
    System.out.println("dubbo provider running...");
    System.in.read();
}

From source file:LotteryDrawing.java

public static void main(String[] args) {
    Scanner in = new Scanner(System.in);

    System.out.print("How many numbers do you need to draw? ");
    int k = in.nextInt();

    System.out.print("What is the highest number you can draw? ");
    int n = in.nextInt();

    // fill an array with numbers 1 2 3 . . . n
    int[] numbers = new int[n];
    for (int i = 0; i < numbers.length; i++)
        numbers[i] = i + 1;//from  w w w.  java 2s .c  om

    // draw k numbers and put them into a second array
    int[] result = new int[k];
    for (int i = 0; i < result.length; i++) {
        // make a random index between 0 and n - 1
        int r = (int) (Math.random() * n);

        // pick the element at the random location
        result[i] = numbers[r];

        // move the last element into the random location
        numbers[r] = numbers[n - 1];
        n--;
    }

    // print the sorted array
    Arrays.sort(result);
    System.out.println("Bet the following combination. It'll make you rich!");
    for (int r : result)
        System.out.println(r);
}