Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Richard Torres   on May 26 In Java Category.

  
Question Answered By: Eloise Lawrence   on May 26

Using the combination of BufferedReader and StringTokenizer...

Here is the example...

import java.io.*;
public class  Token1 {
public static  void main(String[] args) throws  Exception {
double sum=0;
System.out.println("Type two or more numbers  separated by space
to add:(Example: 4 5.6 8.2 2");
//Using BufferedReader recognize the return key input
BufferedReader br = new BufferedReader(new InputStreamReader
(System.in));
String s1 = br.readLine();
//Using string  Tokenizer will split the data  using the
delimiter space.
java.util.StringTokenizer st =new java.util.StringTokenizer
(s1);
while (st.hasMoreTokens()) sum  += Double.parseDouble
(st.nextToken());
System.out.println(" Sum = "+sum);} }

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Input Streams Or get search suggestion and latest updates.


Tagged: