error in taking input from user.

error in taking input from user.

//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!

View Answers

January 24, 2011 at 12:04 PM

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


October 28, 2011 at 8:03 PM

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

October 28, 2011 at 8:06 PM

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









Related Tutorials/Questions & Answers:
error in taking input from user.
error in taking input from user.  //i m having problem inputting the array from user.my program is import java.io.*; class bubble { public static...); } catch (IOException e) { System.out.println("Error!!"); System.exit(1
Java get User Input
Java get User Input       In this section, you will learn how to get the user input from... that will communicate with the user at the command line and returns the user input. We have
Advertisements
escaping user input in php
escaping user input in php  Is it possible to escape the user input while submitting data into database in PHP
Input - Output String Functions
Input - Output String Functions       This tutorial is showing some functions that you need to use for your taking data from a user (text field, text area) since it is not secure to receive
How to read user input in C++
How to read user input in C++  How can i get an input from the users in C++?   You can use the standard input "cin" to get the input from user.. For example: int age; cin >> age
Java User Input
Java User Input  I am using Scanner class for user Input. Scanner s = new Scanner(System.in); String name = s.next(); but i am unable to store full name in name variable...how i can store full name plsss reply   use
calculation after if. user input
user input????   My apologies good evening peoples Once again I am...calculation after if. user input  System.out.print ("please select... addition 5 errors found: File: C:\Users\ Error: variable appleCost might not have
user input to database
in my database user input from my applet does not show...user input to database  /* * Studentinfo2App.java */ package... from the GUI * builder, so this additional configuration is not needed
user input to database
in my database user input from my applet does not show...user input to database  /* * Studentinfo2App.java */ package... from the GUI * builder, so this additional configuration is not needed
user input to database
in my database user input from my applet does not show...user input to database  /* * Studentinfo2App.java */ package... from the GUI * builder, so this additional configuration is not needed
need help with two dimensional array that takes input from user and bubble sorts and selections sorts
need help with two dimensional array that takes input from user and bubble sorts and selections sorts  I can get both of the sorts figured out but i... how many elements are going to be input by the user?   Here is a code
button to accept user input
the radiobutton and spinner.The user input does not show on my Studentinfo.mdb... that accepts firstname, lastname and gender from user and insert to database...button to accept user input  private void jButton1ActionPerformed
Read user input in Java using Scanner
input from console. Our sample program asks user to enter name and then age, user... and Scanner class is one of them. Scanner class can be used to read user input from... class object. Now let's make a simple program to reading user input from
Servlet Error Message based on user input
Servlet Error Message based on user input   ... to check the user input against database and display the message to the user. This example illustrate how to ensure that user input is correct by validating
java user input - Java Beginners
java user input  how to input from keyboard? please give a example.  Hi Friend, There are lot of ways to input data from keyboard.You...:****** try{ System.out.print("Enter String:"); BufferedReader input = new
accept integer from user
accept integer from user  Write an Java application that accepts 100 integer numbers from a user. The input should be in the range of 1-200. Error message needs to be displayed if user entered input which is not in this range
How to take input by user using jDialogue and use that input
this button a dialogue box appear which take employee_id as input from user . then that input be used for fethcing data from the database ( desired table in DB...How to take input by user using jDialogue and use that input  I am
user input in java - Java Beginners
user input in java   i am trying to write a code to compute the average of 5 numbers but i dont know what to do for the program to accept user input  Hi import java.util.*; public class AverageExample { public
XP Bowling Game User input help
XP Bowling Game User input help  I was asked to do the XP Bowling Example as an assignment. I have the programme passing all tests, but now I need to make the code accept input from a user and display the scores/frames
Design a registration.jsp page with input for user registration details
Design a registration.jsp page with input for user registration details  Design a registration.jsp page with input for user registration details like firstname, lastname, choose username, choose password, confirm password. After
function error too many input arguments
function error too many input arguments  function error too many input arguments
chown error invalid user
chown error invalid user  I'm getting the following error on buliding the app in XCode. Can anyone explain me why this error occurred?   Error chown: MYDOMAIN\domain users: Invalid argument Command /usr/sbin/chown
Save the input data until user get changed
Save the input data until user get changed  I would like to know how to store the give input data and perform the calculations even after re-opening the program. I am developing a college library management system, i would like
Save the input data until user get changed
Save the input data until user get changed  I would like to know how to store the give input data and perform the calculations even after re-opening the program. I am developing a college library management system, i would like
Save the input data until user get changed
Save the input data until user get changed  I would like to know how to store the give input data and perform the calculations even after re-opening the program. I am developing a college library management system, i would like
Write a program that takes the marks of user as input
Write a program that takes the marks of user as input  Write a program that takes the marks of user as input. If marks are greater then 60 the program should display "Great, you have passed the course", else the program should
Managing Multiple User Input Data in an Array (or ArrayList)
Managing Multiple User Input Data in an Array (or ArrayList)  Hey... record alphabetically (2) If user chooses choice1, the input data is stored in an ARRAY (or ARRAYLIST) until the user chooses to stop inputting data. Kindly
how to transliterate the input from english to japanese
how to transliterate the input from english to japanese  Hi everyone , I am trying to make an application in java in which i want to get input from user and want to transliterate it in japanese for example : if user types "sa
Display PHP clock with user input date and time
Display PHP clock with user input date and time  The following PHP code displays a clock with current date and time. I want the clock to receive user input date and time. How can this be done? <?php date<em>
Input in Stateless Bean - EJB
Input in Stateless Bean  Hello, I am having problem in taking the input in stateless bean, when I am trying to get integer or double type input from the user in the client file, It shows me the error
Error from struts2.0
Error from struts2.0  Hi All, I run the struts2.0 i get this error please give the solution. My versions jre,jdk,and jvm are 1.6. Tomcat 6.0. My error: The requested resource (/struts2-blank-2.0.6/) is not available. I
Getting ISD code when user input country name
code, from that list i have to read the file and when user input any country name...Getting ISD code when user input country name  I want to create program which user needs by typing Country name he will get ISD code of that country
How to create file from input values in Jframe ?
How to create file from input values in Jframe ?  hi i m doing my project using java desktop application in netbeans.i designed a form to get the user's academic details and on clicking the submit button,it displays all
to read number from user
to read number from user  1)print the positive equivalent of the number 2) check if the no is integer or not 3) find the square root of the number 4) find the cube of the number
JavaScript Array from Input
JavaScript Array from Input   ... you easy to understand an example of  Array from Input. The example create a HTML Page JavaScript array from input include a text name 'name', a text field
how to solve error like'java.lang.NumberFormatException: For input string: "7600113411"' this
how to solve error like'java.lang.NumberFormatException: For input string: "7600113411"' this  java.lang.NumberFormatException: For input string: "7600113411"    java.lang.NumberFormatException: For input string
Count repetitions of every word from an input file
Count repetitions of every word from an input file  Hello..i got to know how can i count the repetitions of every word present in a specific input file?For suppose if i have a url log file which have time,url's,ip address etc
Taking Substring
; In this example we are taking a sub string from a given... this string object as "Rajesh Kumar". We are taking sub string by use... to get certain characters from the big string. Here we are passing the two
input
input  a java program that will exchange the last names of two students that were input by a user
jar file not reading input from serial port
jar file not reading input from serial port  i used a coding for getting data from serial port. JOptionbox with "port not found" message is shown... from comm port. why it is happening? i attached the coding i used. public class
jar file not reading input from serial port
jar file not reading input from serial port  i used a coding for getting data from serial port. JOptionbox with "port not found" message is shown... from comm port. why it is happening? i attached the coding i used. public class
Input From Console
Input From Console     ... and implements flushable interface. The Input from Console is used to access the character... in understanding a code Input from Console. For this we have a class 'Input From Console
Java error reading from file
Java error reading from file   ... are the common error occurred  in java that when the user encounter a corrupt file... In this Tutorial we help you in understanding a n example from Java error
Insert image from user using and save in database
Insert image from user using and save in database  when i am trying to upload a image from user and trying to save into oracle9i database... description The server encountered an internal error () that prevented it from
Excel User Define Error Message
Excel User Define Error Message In this section, you will learn , while cell value validation,  how to show user defined error message using Apache POI... & 30. If you enter other than these value a User  Defined Error
Find Cylinder area By inputting value from user
Find Cylinder area By inputting value from user  Hello Sir I need the code for calculating the area of a cylinder in which it asks radius value from user and then calculate area using this radius value. Please provide me
Simple input application in Echo3
an application which contains the window from where the user can  input a text and this value would be shown into the content pane when user will click... Simple input application in Echo3   
how to pass input from radio button to jsp page
how to pass input from radio button to jsp page  hi.. the code below... are matched from database. I want to pass the selected value in Struts Action FormBean..."><label> <input name="radiobutton" type="radio" value
how to pass input from radio button to jsp page
how to pass input from radio button to jsp page  hi.. the code below... are matched from database. I want to pass the selected value in Struts Action FormBean..."><label> <input name="radiobutton" type="radio" value
how to pass input from radio button to jsp page
how to pass input from radio button to jsp page  hi.. the code below... are matched from database. I want to pass the selected value in Struts Action FormBean..."><label> <input name="radiobutton" type="radio" value

Ads