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));
}
}

Advertisement

~ by ke sopha on February 25, 2009.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.