Solved

Issue in Java Code

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB Script to add site to Java Exception List 4 76
javap bin 2 34
web services creation SOAP vs REST 5 39
even odd program using while loop 3 40
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
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 …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

776 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