Home Answers Viewqa Java-Beginners error in taking input from user.

 
 


Arti Kumari
error in taking input from user.
3 Answer(s)      2 years and 4 months ago
Posted in : Java Beginners

//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 Pages:
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
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
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
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
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
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
input output
data types from the input stream in a machine format.... FileInputStream It contains the input byte from a file... input to read the user input.. In this section, you will see how the standard I
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
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 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
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
Keyboard Input
input from the user. GUI (Graphical User Interface). Displaying a graphical text... for reading from text files. Graphical User Interface This is how... input - reading from System.in Console input is rarely used in real programs
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
input
input  a java program that will exchange the last names of two students that were input by a user
Input And Output
This class reads the primitive data types from the input stream... byte from a file and implements an input stream... standard input to read the user input.. In this section, you will see how
Mysqldump one table - Taking dump of only one table
Use of mysqldump for taking backup of one table In this section you will see... user requirement. You can specify the name of table be backup in while executing... from the mydatabase, then you can issue the following command on the console
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
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
Taking Substring
Taking  Substring       In this example we are taking a sub string from a given string... this string object as "Rajesh Kumar". We are taking sub string by use
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
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
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
Dialog and Console Input-Output
, but it also gets input from the user. 1 2 3 4 5 6 7 8... that also accepts user input. It returns a string that can be stored... and file input. Of course, your program should eventually have a GUI user
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
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
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
input - Java Beginners
input  i want to know how to take value from user in core java.help me soon.  Hi Friend, There are lot of ways to input data.You can use... to input the data from the command prompt. Try the following code to input name
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
Command Line Standard Input In Java
) { System.out.println("Error reading from user... be read from the keyboard input, file input or any other input source depends...Command Line Standard Input In Java In this section we will discuss about
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
Change the user input to integer
Change the user input to integer   ... method show() is taking two variables as input and second method calculate... will create a object of a Rectangle class. Now we ask the user to input two values
iPhone Input Field, iPhone Input Field Tutorial
iPhone Input Field Generally, input fields are used to take input from the users.  In iPhone application we can use Text Field to take the input. .... That keyboard can be customize according to our need i.e. if we wants the user
error at programming
;<td><input type="text" name="user"></td></tr> <tr>...error at programming  <p>import javax.servlet.http.*; import...=s.executeQuery("select * from emp ");</p> <p>if(rs.next()) {</p>
javascript focus input
the example below. It has two input fields to take name and address as input from... whether user has entered some value to the input boxes one by one. If any one... javascript focus input
Dialog Box Input Loop
When reading input in a loop user must have some way of indicating that the end... of the input is for the user to enter a special value to indicate... from the input. This may not be a problem in many cases, but it can
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   
Convert Inputstream to OutputStream
by taking an example. In this example we are taking a file as input stream... into output stream we read a single character from input stream... is used to obtain input bytes from a file in a file system
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
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
Developing User Registration Form
from the user.     Result Page: The result page displays... registering the user, Registration Form is displayed again indicating the error... to the user to take the input. Here is the code of the userRegister.jsp file
Validating User in JSP
server. UserValidation.jsp is taking input through the user and then after taking.... These temporary variables are responsible for validating user input. Code...;/b>&nbsp;&nbsp; &nbsp;&nbsp;<input type="text" name="user
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
Array and input
[ ]={1,2,3,4,5,6,7,8,9,10,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26}; i want to ask user to input one of the above numbers then i want to print the array without the number user input. how will i do tht

Ask Questions?

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.