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
Solved

Issue in Java Code

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xampp tool 12 56
spring jars download 1 35
ejb example issues 3 21
hashmap order 17 36
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

840 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