Results 1 to 4 of 4

Thread: StreamError

  1. #1
    mm2236 is offline Member
    Join Date
    Sep 2008
    Posts
    9
    Rep Power
    0

    Default StreamError

    Hi
    i want read double precision floating point numbers from the keyboard two (2) at a time. The program should read a total of three lines (3) lines for a total of six (6) numbers into a double array. After the six numbers are read the program should print all of the numbers one per line and then print the string “Maximum =” followed by the maximum of the numbers entered. On the following line print the string “Minimum =” followed by the minimum of the numbers entered. An example output is:
    C:\> java Numbers
    1.23 -2.4
    10002 11.12
    0.001 -2.0
    1.23
    -2.4
    … (rest of numbers here)
    -2.0
    Maximum = 10002
    Minimum = -2.4

    but i have problem :
    Java Code:
    import java.io.*;
    
    class SumDif {
        StreamTokenizer in;
    
        PrintWriter out;
    
        Double nextDouble() throws IOException {
            in.nextToken();
            return in.nval;
        }
    
        static double inputDouble[];
    
        void run() throws IOException {
            in = new StreamTokenizer(new BufferedReader(new
                    InputStreamReader(System.in)));
            out = new PrintWriter(new OutputStreamWriter(System.out));
            inputDouble[0]=nextDouble();
            inputDouble[1]=nextDouble();
            inputDouble[2]=nextDouble();
            inputDouble[3]=nextDouble();
            inputDouble[4]=nextDouble();
            inputDouble[5]=nextDouble();
        }
    
        static double max(double... numbers) {
            double maximum = Double.MIN_VALUE;
            for (double number : numbers)
                if (number > maximum)
                    maximum = number;
            return maximum;
        }
    
        static double min(double... numbers) {
            double minimum = Double.MAX_VALUE;
            for (double number : numbers)
                if (number < minimum)
                    minimum = number;
            return minimum;
        }
    
        public static void main(String[] args) throws IOException {
            new SumDif().run();
            for (int i=0;i<inputDouble.length;i++){
                System.out.println("max"+max(inputDouble[i]));
                System.out.println("min"+min(inputDouble[i]));
            }
        }
    }
    please help me ...

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,390
    Rep Power
    25

    Default

    but i have problem
    What is the problem?
    Please show the problem and explain it.

  3. #3
    satu is offline Member
    Join Date
    Aug 2008
    Posts
    12
    Rep Power
    0

    Default

    please specify your problem with suitable error output.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    If I'm get you correctly, you need to read multiple line from the command prompt. As far as I know it's not possible in Java. You can read multiple arguments in Java.

    Anyway, as others are mentioned here better to explain your question clearly.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •