Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Thursday, February 28, 2008

Input through Keyboard

/*The following program is written in a very simple form to show the keyboard input from the programmer which
returns the corresponding value conditioned by the if-statement in the method min(int, int) */

import java.io.*;

public class KeyBoardInput {

public static int min( int a, int b) {

if (a <= b)
return a;
else
return b;
}

public static void main(String[] args) throws IOException {

int x;
int y;

String sb;
String ks;

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

System.out.println ("Enter x ");

sb = bk.readLine();
x = Integer.parseInt(sb);

System.out.println("Enter y");

ks = bk.readLine();
y = Integer.parseInt(ks);

bk.close();

System.out.print("The returned value is = ");
System.out.println(Math.min(x * 5, y + 20));
}
}

No comments:

Post a Comment