Solved

Issue in Java Code

Posted on 2010-11-25
4
318 Views
Last Modified: 2012-08-13
Hi

Iam beginner in using Java and the attached file has a Java code is not functioning and i am not able to catch the issue

can someone help me with it
Regards

AssigOne510.java
0
Comment
Question by:nadermik
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 34213639
What does 'not functioning' mean?
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 34213653
use try catch in your code then .... you can find out
0
 
LVL 92

Assisted Solution

by:objects
objects earned 250 total points
ID: 34214521
0
 
LVL 11

Accepted Solution

by:
Bruce Smith earned 250 total points
ID: 34215755
You have a lot of extraneous code here but I think you need to be more clear on your question. Also use the Code Embed feature so we don't have to download source.

But your problem (I think) lies toward the end when you say:  
if (i == 0) {
                        System.out.println("The first number is: " + output);
                    }
                    if (i == 1) {
                        System.out.println("The second number is: " + output);
                    }
                    if (i == 2) {
                        System.out.println("The sum is: " + output);
                    }

Open in new window


The variable 'output' is an empty String "". You need to change all of these to the numbers captured from the Scanner which are num1 and num2. Then you need to add these together like so (num1+num2). See here:
if (i == 0) {
                        System.out.println("The first number is: " + num1);
                    }
                    if (i == 1) {
                        System.out.println("The second number is: " + num2);
                    }
                    if (i == 2) {
                        System.out.println("The sum is: " + (num1 + num2));
                    }

Open in new window


This will at least print the inputted numbers out and add them. You really need to simplify your code and learn how to use loop structures to your advantage, not just for fun.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
hibernate example issues from command prompt 10 63
add projects t working set in maven 2 37
wild fly 8 startup error 2 37
American Express @Work site and Java 4 63
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question