Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Exercise

  1. #1
    Member
    Join Date
    May 2013
    Posts
    165
    Thanks
    58
    Thanked 1 Time in 1 Post

    Default Exercise

    I'm running the following code in my editor for the following exercise: Sphere Online Judge (SPOJ) - Problem ADUN
    Seems to run fine in my editor though I am being judged as giving the wrong answer, where am I going wrong?
    import java.io.*;
    import java.math.BigInteger;
    import java.util.Scanner;
     
     class AddingTwoNumbers{
     
     
    	public static void main(String[] args)throws Exception{
    		try{
    		Scanner scanner = new Scanner(System.in);
    		Scanner scanner2 = new Scanner(System.in);
    		BigInteger count = scanner.nextBigInteger();
    		BigInteger count1 = scanner2.nextBigInteger();
    		System.out.println(addingNumbers(count,count1));
     
    		}catch(Exception e){
    			return;
    		}
    		}
     
    	public static BigInteger addingNumbers(BigInteger firstLine, BigInteger secondLine){
    		return firstLine.add(secondLine);
    	}
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Exercise

    giving the wrong answer
    Can you post the answer your code gives and what the correct answer is?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    May 2013
    Posts
    165
    Thanks
    58
    Thanked 1 Time in 1 Post

    Default Re: Exercise

    As in the example when code is given input 10 and 20, ouput is 30. So seems good plus I've tried the code with much larger numbers and works though keep getting errors like NZEC/ wrong answer/ compilation. It's my first time using spoj so getting frustrated.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Exercise

    Can you post some examples of wrong output from your code and show what the correct output should be?

    I have never heard of spoj.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    May 2013
    Posts
    165
    Thanks
    58
    Thanked 1 Time in 1 Post

    Default Re: Exercise

    That's the trouble there is no wrong output in my editor, spoj is basically a challenge site which evaluates my code based on problems.
    Thanks anyway, I've decided to give up spoj.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Exercise

    It's hard to fix a problem if you don't have samples of what is wrong and what is correct.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Help with exercise.
    By javapol in forum What's Wrong With My Code?
    Replies: 7
    Last Post: February 8th, 2013, 09:40 PM
  2. Java exercise
    By nhiap6 in forum Java Theory & Questions
    Replies: 1
    Last Post: January 2nd, 2013, 11:04 AM
  3. Exercise
    By phite2009 in forum Member Introductions
    Replies: 3
    Last Post: September 30th, 2011, 08:51 AM
  4. Is this what my exercise want?
    By Arkeshen in forum Java Theory & Questions
    Replies: 3
    Last Post: May 16th, 2011, 04:51 PM
  5. Exercise problems
    By Virgildonatifan in forum Java Theory & Questions
    Replies: 0
    Last Post: February 14th, 2010, 04:12 AM