Inputting characters from the keyboard in applications should include code, such as the code in the following program that defines a method called minMax. MinMax takes two integers and creates an array that is populated with all integers between the two integers.
1 import java.io.*;
2 public class KeyBoardInput
3 {
4
5 int[] minMax(int lower, int upper)
6
7 { int arr[]=new int[(upper-lower) + 1];
8
9 for (int i=0; i<arr.length; i++)
10 {
11 arr[i] = lower++;
12 }
13 return arr;
14 }
15 public static void main (String args[])throws Exception
16 {
17 InputStreamReader reader =new InputStreamReader(System.in);
18
19 BufferedReader input=new BufferedReader(reader);
20
21 System.out.println("Please enter a number");
22
23 String letters= input.readLine();
24
25 int numbers =Integer.parseInt(letters);
26
27 System.out.println("Please enter the upper number");
28
29 String moreInput =input.readLine();
30
31 int moreNumbers=Integer.parseInt(moreInput);
32
33 int theArray[];
34
35 KeyBoardInput theRange=new KeyBoardInput();
36
37 theArray = theRange.minMax(numbers, moreNumbers);
38
39 System.out.print("The array:[ ");
40 for(int i=0;i<theArray.length;i++)
41 {
42 System.out.print(theArray[i]+"");
43 }
44 System.out.println("]");
45 }