Skip to content

Instantly share code, notes, and snippets.

@kranthilakum
Created April 10, 2013 17:32
Show Gist options
  • Save kranthilakum/5356694 to your computer and use it in GitHub Desktop.
Save kranthilakum/5356694 to your computer and use it in GitHub Desktop.
A simple example to read input from console using BufferedReader and InputStreamReader.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class ReadInput {
public static void main(String[] args)throws IOException {
int age = 0;
boolean married = false;
String gender = null;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
System.out.println("enter age:");
age = Integer.parseInt(br.readLine());
System.out.println("eneter married :");
married = Boolean.parseBoolean(br.readLine());
System.out.println("enter gender :");
gender = br.readLine();
}
catch(Throwable e) {
e.printStackTrace();
}
System.out.println("enter age:" +age);
System.out.println("eneter married :" +married);
System.out.println("enter gender :" +gender);
perdetails (age, gender, married);
}
private static int perdetails(int age, String gender, boolean married) {
int premimum = 300;
if((age < 25) && (gender.equals("male")) && (!married)){
premimum = premimum + 1000;
}
else{
if (married || gender.equals("female")){
premimum = premimum - 100;
if((age >= 46) && (age <= 65)){
premimum = premimum - 150;
}
}
}
System.out.println("premimum" + premimum);
return premimum;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment