Solved

Issue in Java Code

Posted on 2010-11-25
4
314 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
Comment Utility
What does 'not functioning' mean?
0
 
LVL 20

Expert Comment

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

Assisted Solution

by:objects
objects earned 250 total points
Comment Utility
0
 
LVL 11

Accepted Solution

by:
patsmitty earned 250 total points
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

762 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

12 Experts available now in Live!

Get 1:1 Help Now