Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8663855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:05:34+00:00 2026-06-12T17:05:34+00:00

I am working on a Server Client program in Java, using Sockets. I ask

  • 0

I am working on a Server Client program in Java, using Sockets.

I ask the user to input a series of integers, add them in an ArrayList and send them over to the server as an Object using ObjectOutputStream. The Server then receives the object.

I parse the object as an ArrayList and then I use a method to calculate what is the maximum number of the integers and return it as a string to the client.

I am using BufferedReader for the user input

In a sense what I need is a logic on how to:

To check for the users input, if it is not “Ok” or press Enter

The user should be able to add numbers separated by a space.

If then he presses Enter then should exit the loop and the numbers add at the array

I have so far:

 BufferedReader integers = new BufferedReader(new InputStreamReader(System.in));
                        //  send int 1, for the Max number option
                        pw.println(option);
                        System.out.println(br.readLine());
                        String x = integers.readLine();
                        if(integers!=null){

                            readInt(integers);

                    }


                        objectOut = new ObjectOutputStream(client.getOutputStream());
                        objectOut.writeObject(maxNum);
                        objectOut.flush();
                        System.out.println(br.readLine());
                        objectOut.close();
                        break;

The readIn method:

public static int readInt(BufferedReader stdIn) {
        while (true) {
            try {
                String line = stdIn.readLine();
                int value = Integer.parseInt(line);
                return value;
            } catch (java.lang.NumberFormatException e) {
                ;
            } catch (IOException e) {
                ;
            }
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T17:05:36+00:00Added an answer on June 12, 2026 at 5:05 pm

    You can better handle this with Scanner. BufferedReader is quite old and deprecated.

    List<Integer> seriesOfInt = new ArrayList<>();
    
    while (scanner.hasNextInt()) {
        seriesOfInt.add(scanner.nextInt());
    }
    

    Or, if user is entering all those numbers in one line with some delimiter between them, say a whitespace (), you can split the input and store in ArrayList..

    if (scanner.hasNext()) {
        List<String> seriesOfIntString = Arrays.asList(scanner.next().split(" "));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on a client/server based Java-program for a customer. I googled a
I am working on a server/client communication program and I am stuck at a
I got a working server in C# and a working client in Java (Android).
I started to program client/server applications in J2ME recently.Now I'm working with c++ builder
I am working on a simple client/server program and for now all it is
I am working on a SSL client server program and I have to reuse
I'm working on a client-server program for the first time, and I'm feeling woefully
I'm working on a chat program where the client is single-threaded but the server
I'm using a Java program to POST some XML data from a remote client
I am using Selenium Server (v2.21) and Selenium Java Client (v.2.21.0) to automate a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.