error in taking input from user.

Ads

 
 

Share on Google+Share on Google+

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

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

Ads









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
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
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
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
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
Tutorials   
Java Spring Hibernate Struts Training What type of programming language is Java? How do beginners learn about Java? ClassNotFoundException HttpRequestInterceptor java.lang.noclassdeffounderror: org/apache/http/httprequest noclassdeffounderror: org/apache/http/client/methods/httpurirequest java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient How do I resolve this Java Class not found exception? httpclient java.lang.NoClassDefFoundError Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017

Ads

 
Advertisement null

Ads