The below code is not working as after providing the size integer there is an error displayed.
Error
Exception in thread "main" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at ARR.Number(Arr.java:13)
at ARR1.main(Arr.java:42)'
Java Program
import java.io.BufferedReader;
import java.io.IOException;
class ARR
{
public static BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in));
int arr[];
void Number (int n) throws IOException
{
for (int i=0; i<n; i++)
{
arr[i]= Integer.parseInt(br1.readLine());
}
}
void display(int n)
{
for (int i=0; i<n; i++)
{
System.out.print(arr[i]+"\t");
}
}
void Search(int n,int num)
{
for (int i=0; i<n; i++)
{
if (arr[i]== num)
{
System.out.println("Number Found");
}
}
}
}
class ARR1
{
public static void main (String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
ARR obj = new ARR();
System.out.println("Enter No size: " );
int a = Integer.parseInt(br.readLine());
obj.Number(a);
obj.display(a);
System.out.println();
System.out.println("Enter the Number to search:");
int b= Integer.parseInt(br.readLine());
obj.Search(a,b);
}
}