Solved

Issue in Java Code

Posted on 2010-11-25
4
315 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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:

912 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now