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

  • Home
  • SEARCH
  • 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 829857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:56:52+00:00 2026-05-15T03:56:52+00:00

I am actually new to java programming and am finding it difficult to take

  • 0

I am actually new to java programming and am finding it difficult to take integer input and storing it in variables…i would like it if someone could tell me how to do it or provide with an example like adding two numbers given by the user..

  • 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-05-15T03:56:53+00:00Added an answer on May 15, 2026 at 3:56 am

    Here’s my entry, complete with fairly robust error handling and resource management:

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    
    /**
     * Simple demonstration of a reader
     *
     * @author jasonmp85
     *
     */
    public class ReaderClass {
    
        /**
         * Reads two integers from standard in and prints their sum
         *
         * @param args
         *            unused
         */
        public static void main(String[] args) {
            // System.in is standard in. It's an InputStream, which means
            // the methods on it all deal with reading bytes. We want
            // to read characters, so we'll wrap it in an
            // InputStreamReader, which can read characters into a buffer
            InputStreamReader isReader = new InputStreamReader(System.in);
    
            // but even that's not good enough. BufferedReader will
            // buffer the input so we can read line-by-line, freeing
            // us from manually getting each character and having
            // to deal with things like backspace, etc.
            // It wraps our InputStreamReader
            BufferedReader reader = new BufferedReader(isReader);
            try {
                System.out.println("Please enter a number:");
                int firstInt = readInt(reader);
    
                System.out.println("Please enter a second number:");
                int secondInt = readInt(reader);
    
                // printf uses a format string to print values
                System.out.printf("%d + %d = %d",
                                  firstInt, secondInt, firstInt + secondInt);
            } catch (IOException ioe) {
                // IOException is thrown if a reader error occurs
                System.err.println("An error occurred reading from the reader, "
                                   + ioe);
    
                // exit with a non-zero status to signal failure
                System.exit(-1);
            } finally {
                try {
                    // the finally block gives us a place to ensure that
                    // we clean up all our resources, namely our reader
                    reader.close();
                } catch (IOException ioe) {
                    // but even that might throw an error
                    System.err.println("An error occurred closing the reader, "
                                       + ioe);
                    System.exit(-1);
                }
            }
    
        }
    
        private static int readInt(BufferedReader reader) throws IOException {
            while (true) {
                try {
                    // Integer.parseInt turns a string into an int
                    return Integer.parseInt(reader.readLine());
                } catch (NumberFormatException nfe) {
                    // but it throws an exception if the String doesn't look
                    // like any integer it recognizes
                    System.out.println("That's not a number! Try again.");
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 506k
  • Answers 506k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Math .NET may be will be interesting for you. May 16, 2026 at 3:34 pm
  • Editorial Team
    Editorial Team added an answer Fixed it by extends SoapClient and overrides __doRequest() method where… May 16, 2026 at 3:34 pm
  • Editorial Team
    Editorial Team added an answer Your task doesn't know which application's factories.yml to load -… May 16, 2026 at 3:34 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm new to Java programming. I am curious about speed of execution and also
I'm a Java/J2ee programmer working in India. I'm very passionate about programming and I
Scenario: a program running in a byte code virtual machine like Java or Python,
I would like to write an app on Android to upload my GPS location
I am writing a multi-threaded application in Java in order to improve performance over
I'm writing an windforms application using .NET (actually IronPython, but that's not relevant), and
So I've been reading Effective Java by Joshua Bloch and noticed two points which
Curious what the best way is in Java to get the mime-type of a
I am using the Java Native Interface to include some statically compiled code in
Here's an excerpt from java.text.CharacterIterator documentation: This interface defines a protocol for bidirectional iteration

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.