• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 195
  • Last Modified:

Accepting a value

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;
            for(i=0;i<5;i++)
            {
                  System.out.print("Enter the number " + i+1)
                  *******************************
            }
      }
}
0
rmvprasad
Asked:
rmvprasad
  • 2
1 Solution
 
objectsCommented:
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String input = in.readLine();
0
 
objectsCommented:
To then convert it to a double use:

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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now