Accepting a value

Posted on 2004-11-03
Last Modified: 2010-03-31
How to accept a value in java as we do scanf in c language and cin in c++.
I felt like declaring an array of 5 int and entering the values manually at run time. I could declare the array but not accept the values. Thank You.

class example
      public static void main(String args[])
            double num[];
            num=new double[5];
            double result=0;
            int i;
                  System.out.print("Enter the number " + i+1)
Question by:rmvprasad
    LVL 92

    Accepted Solution

    BufferedReader in = new BufferedReader(new InputStreamReader(;
    String input = in.readLine();
    LVL 92

    Expert Comment

    To then convert it to a double use:

    num[i] = Double.parseDouble(input);

    Featured Post

    Live: Real-Time Solutions, Start Here

    Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

    Join & Write a Comment

    Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues undeā€¦
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilationā€¦
    Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
    This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now