Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8993711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:15:13+00:00 2026-06-15T23:15:13+00:00

My code is getting this error: Skriv din alder herunder og tryk enter: Exception

  • 0

My code is getting this error:

Skriv din alder herunder og tryk enter:
Exception in thread "main" java.util.NoSuchElementException
    at java.util.Scanner.throwFor(Scanner.java:907)
    at java.util.Scanner.next(Scanner.java:1530)
    at java.util.Scanner.nextInt(Scanner.java:2160)
    at java.util.Scanner.nextInt(Scanner.java:2119)
    at Tasteturindtastning.main(Tasteturindtastning.java:20)
[Finished in 1.7s with exit code 1]

And my code is:

// Starter java som man plejer, læs i HejVerden.java

public class Tasteturindtastning
{
    public static void main(String[] arg)
    {
        /* Jeg skal nu angive en variable, men jeg kan ikke bestemme denne variable
         * Da jeg ønsker at indtastningen fra dette tastetur skal være variablen.
         * I stedet for int og double bruger jeg så java.util.Scanner, som aflæser
         * brugerens indtastninger.
         */

        java.util.Scanner tastetur = new java.util.Scanner(System.in);

        // Printer en opgave/spørgsmål til brugeren

        System.out.println("Skriv din alder herunder og tryk enter:");

        int alder; // Angiver et variablenavn
        alder = tastetur.nextInt(); // Angiver variablen med værdien fra indtastningen

        /* Herunder gør jeg brug af et if statement der tjekker værdien for
         * variablen alder, og ser om den er lig med eller højere end 18, og hvis
         * dette er tilfældet, så udprinter den en sætning
         */

        if (alder >= 18) System.out.println("Du er myndig, da du er " + alder + " år gammel"); // Printes hvis han er 18 eller ældre

    }
}

What is wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:15:14+00:00Added an answer on June 15, 2026 at 11:15 pm

    NoSuchElementException is thrown by the scanner when there are no more elements to read from the scanner.you will have to check if any elements exists in the scanner before retrieving the Integers using Scanner.hsNextInt()

           while(tastetur.hasnextInt()){
            alder = tastetur.nextInt(); 
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting this error in java in my junit test code. I looked
I'm getting this error when running this code: Fatal error: Uncaught exception 'DOMException' with
I found a client/server code and I am getting this error: java.net.SocketException: Software caused
Am getting this error for my code: Undefined symbols for architecture x86_64: _spendDollars, referenced
I'm getting this error message with the code below: class Money { public: Money(float
I am getting this error here is my code if(isset($_POST['submit'])) { $projTit=mysql_escape_string($_POST['projecttitle']); $projCat=mysql_escape_string($_POST['projectcategory']); $budget=intval(mysql_escape_string($_POST['budget']));
I am getting this error when I run the following code: #!/usr/bin/env ruby -rubygems
I keep getting this error System.Web.HttpException was unhandled by user code Message=Validation of viewstate
I am getting this error when I try to build for the device: Code
I keep getting this error whenever I call gethostbyname() in my C code. ==7983==

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.