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 2 of 2

Thread: java.util.NoSuchElementException

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default java.util.NoSuchElementException

    So basically this is an assignment, and i am getting the correct results when i put in my answer, however, which the system i am submitting my code to tries to enter something it receives an error saying "java.util.NoSuchElementException - ". Any ideas on whats going on? All is fine and dandy on my end :s

    import java.util.Scanner;

    public class SimpleCalc {

    /**
    @author Andrew Howard - 430365526
    */
    public static void main(String[] args) {
    Scanner keyboard = new Scanner(System.in);/**preparing for input*/
    long n = keyboard.nextLong();/** n has been used as it was what the variable name used in the assesment description*/
    if (n < 0){ /**numbers less than zero*/
    System.out.println(n*n+n/2);
    }
    if (n >= 0 ) {/**number greater than or equal to zero*/
    if (n % 2 == 0){/**determines whether a number is even*/
    System.out.println((n*n*n*(n-1)));
    }
    else {/** else is used for numbers that are not even, i.e.; odd*/
    System.out.println((1/n)+3*n);
    }
    }

    }

    }

  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: java.util.NoSuchElementException

    Please copy the full text of the error messages and paste it here.

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 11
    Last Post: August 30th, 2012, 02:30 PM
  2. NoSuchElementException
    By chantal001 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 30th, 2011, 11:13 AM
  3. using java.util.InputMismatchException with try
    By itayj in forum What's Wrong With My Code?
    Replies: 16
    Last Post: October 26th, 2011, 06:24 PM
  4. Replies: 3
    Last Post: April 26th, 2011, 02:51 AM
  5. java.util.ConcurrentModificationException Issue
    By joshuaa in forum Collections and Generics
    Replies: 1
    Last Post: December 2nd, 2010, 04:41 PM