Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Arti Kumari
error in taking input from user.
3 Answer(s)      3 years and 10 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!


Advertisement
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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>
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
function error too many input arguments
function error too many input arguments  function error too many input arguments
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... are using the substring() method to get certain characters from the big string
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 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
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
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
 

 

 

DMCA.com