Wednesday 12 August 2015

3 ways to take inputs in java (Scanner , console , BufferedReader )

import java.util.*;

import java.io.Console;

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



class Input
{
 public static void main(String []args) throws IOException
 {
  Scanner a = new Scanner(System.in); // creating object of scanner class
  String s=a.nextLine();              // way to take input through Scanner(nextLine for String)
  System.out.println(s);
  int i=a.nextInt();                  // way to take input through Scanner(nextInt for int)
  System.out.println(i);


  String str=System.console().readLine();  // way to take input from console
  System.out.println(str);



  BufferedReader in = new BufferedReader( new InputStreamReader(System.in)); // creating object of BufferedReader
  String str1 = in.readLine();      
  System.out.println(str1);
  int num = Integer.parseInt(in.readLine());
  System.out.println(num);

 }
}

No comments:

Post a Comment

Uploading and Running Lambda function in AWS

Main.go package main import ( "fmt" "encoding/json" "log" "github.com/aws/aws-lambda-g...