
//i m having problem inputting the array from user.my program is
import java.io.*;
class bubble {
public static void main(String args[]) {
int a[]=new int[20];
int i=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter 10 no. to sort");
try {
do
{
a[i]=(int)br.read();
i++;
}while(i<10);
}
catch (IOException e)
{
System.out.println("Error!!");
System.exit(1);
}
}
}
//above program is taking only 4 values.
please suggest solution soon. tell me the faults in it!

Hi Friend,
Try this:
import java.io.*;
import java.util.*;
class bubble {
public static void main(String args[]) throws Exception{
int a[]=new int[10];
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter 10 no. to sort");
for(int i=0;i<a.length;i++){
a[i]=Integer.parseInt(br.readLine());
}
Arrays.sort(a);
System.out.println("Sorted Array: ");
for(int i=0;i<a.length;i++){
System.out.println(a[i]);
}
}
}
Thanks

import java.io.*;
class Inpt {
public static void main(String args[])
{
int i=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter 10 no. to sort");
int a[]=new int[20];
try {
do {
System.out.println("tacking "+i+" input ");
a[i]=Integer.parseInt(br.readLine()); //use parsing concept
i++;
}
while(i<10);
} catch (IOException e)
{ System.out.println("Error!!");
System.exit(1);
}
}
}

//use parsing while taking input from user...
dont try to type cast buffer input
import java.io.*;
class Inpt {
public static void main(String args[])
{
int i=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter 10 no. to sort");
int a[]=new int[20];
try {
do {
System.out.println("tacking "+i+" input ");
a[i]=Integer.parseInt(br.readLine());
i++;
}
while(i<10);
} catch (IOException e)
{ System.out.println("Error!!");
System.exit(1);
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.