-5

How can I store float value in an array from command line and when user input character "q" then system stop inputting values from command line.

Beau Grantham
  • 3,435
  • 5
  • 33
  • 43
user1703737
  • 533
  • 1
  • 11
  • 25
  • 1
    You need to write a little program using `Scanner.java`. Read one token at a time, exit when it's q otherwise parse into float and store in a float array. – Yogendra Singh May 14 '13 at 17:11
  • In addition to @YogendraSingh, I would paste those values into List, which you will then can [convert to array](http://stackoverflow.com/questions/9572795/convert-list-to-array-in-java) – om-nom-nom May 14 '13 at 17:13
  • 1
    Seems like your life depends on this code. – Sotirios Delimanolis May 14 '13 at 17:14
  • In order to answer this question, we'll need more specific information. How should the array be entered, and what is the dimension of the array (i. e., is it a 2-dimensional array or a 1-dimensional array)? – Anderson Green May 14 '13 at 17:31
  • Dear Green! its only 1-dimensional float array but size of the array is not know in advance – user1703737 May 14 '13 at 17:43

1 Answers1

0

I haven't tested it, but wrote using Scanner docs

Scanner sc = new Scanner(System.in);
while(sc.hasNext()) {
  String next = sc.next();
  if("q".equals(next)) break;

  float value = new Float(next);
  System.out.println("Float: "+value);
}
mprivat
  • 21,582
  • 4
  • 54
  • 64