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 8215217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:42:35+00:00 2026-06-07T11:42:35+00:00

String[] names=new String[4]; int[] scores=new int[4]; Scanner keyboard = new Scanner(System.in); System.out.println(Enter 4 strings

  • 0
String[] names=new String[4];
int[] scores=new int[4];
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter 4 strings and integers:");
for(int i=0;i<4;i++){
  names[i]=keyboard.nextLine();
  scores[i]= keyboard.nextInt();
}

Above is my simple program and the following shows the exception that pops up.

Enter 4 strings and integers:
first
1
second
Exception in thread "main" java.util.InputMismatchException
    at java.util.Scanner.throwFor(Scanner.java:909)
    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 Q2.main(Q2.java:15)
Java Result: 1
  • 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-07T11:42:36+00:00Added an answer on June 7, 2026 at 11:42 am

    nextInt doesn’t swallow the end of line, that stays in the buffer. So when you hit 1enter, 1 is read into the first score, then the second name is set to an empty string.

    Then the parser tries to interpret second as an int, raising the exception.

    You’ll need to discard the current line after the readInt.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class A (names: String*) { val namesBuffer: ListBuffer[String] = new ListBuffer[String] } I was
say I have a list of names var names = new List<string>{Tom, Dick, Harry};
I have a an array of strings:e.g: string [] names ={P,A,B,G,F,K,R} I have another
i used this code: List<string> lists=new List<string>(apple,orange,banana,apple,mang0,orange); string names; names=lists.Distinct() is that correct?
I have the following simple shema: var userSchema = new Schema({ name : String,
public string Process<T>(string name, string address) { var dataObj= new Data<T>(); List<T> currentList= dataObj.GetAll(name);
My model: public class Father { Set<Son> sons = new HashSet<Son>(); String name =
I have this code: con.Open(); cmd = new MySqlCommand(String.Format(SELECT concat(name,'|',lastname) FROM {0} WHERE ID=
Consider the below String String names = Bharath-Vinayak-Harish-Punith I want to get output in
How to sort string names in array on ascending order . I tried sort

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.