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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:24:45+00:00 2026-06-15T07:24:45+00:00

Here is the code: import java.util.Scanner; public class Array2 { static Scanner input =

  • 0

Here is the code:

import java.util.Scanner;
public class Array2 
{
  static Scanner input = new Scanner ( System.in );

  public static void main ( String [] args )
  {
    String [] studentNames = new String [5];
    student_Names ( studentNames );
  }

  public static void student_Names ( String [] studentNames )
  { 
    for ( int x = 0; x < studentNames.length; x++ )
    {
      System.out.printf( "\nStudent %d name : ", x+1);
      studentNames[x] = input.nextLine();
      student_Scores();
    }
  }

  public static void student_Scores ()
  {
    double [] studentScores = new double [4];
    int x;
    for ( x = 0; x < studentScores.length; x++ )
    {
      System.out.printf( "\nEnter marks for test %d: ",x+1 );
      studentScores[x] = input.nextDouble();
    }
    average_Scores( studentScores );
  }

  public static void average_Scores( double [] a )
  {
    int i;
    double sum, average;
    for ( i = 0, sum = 0; i < a.length; i++ )
    {
      System.out.printf("Marks Test %d : %.2f\n", i+1, a[i]);
    }

    for ( i = 0, sum = 0; i < a.length; i++ )
    {
      sum = sum + a[i];
    }
    average = sum / a.length;
    student_Grades ( average );
    System.out.printf("\nAverage Score : %.2f", average);
  }

  public static void student_Grades ( double b )
  {
    String c = "";
    if ( b > 0 && b < 60)
      c = "F";
    if ( b >= 60 && b < 70)
      c = "D";
    if ( b >= 70 && b < 80)
      c = "C";
    if ( b >= 80 && b < 90)
      c = "B";
    if ( b >= 90 && b <= 100)
      c = "A";
    System.out.printf("\nGrade         : %s", c);
  }
}

And this is the output when this is execute:

Student 1 name : sss

Enter marks for test 1: 12

Enter marks for test 2: 23

Enter marks for test 3: 34

Enter marks for test 4: 45
Marks Test 1 : 12.00
Marks Test 2 : 23.00
Marks Test 3 : 34.00
Marks Test 4 : 45.00

Grade         : F
Average Score : 28.50
Student 2 name : 
Enter marks for test 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-15T07:24:46+00:00Added an answer on June 15, 2026 at 7:24 am

    Your issue can be found in the method student_Names; instead of:

    studentNames[x] = input.nextLine();
    

    Use

    if(x>0) input.nextLine();
    studentNames[x] = input.nextLine();
    

    Your issue comes from Java mistakingly believing that the user has already given the input for the next name; input.nextLine(); basically takes this input and throws it away, returning things back to their natural state.

    Since name input works fine for the first student, however, the if(x>0) statement is necessary to make this apply only to the rest of the student names.

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

Sidebar

Related Questions

Here is my code: import java.util.Scanner; public class BankAccount1 { public static void main(String[]
Here's my code: import java.util.Scanner; public class Arrays { public static void main(String[] args)
Here's my code: import java.util.Scanner; import static java.lang.System.*; public class GuessingGame { private int
import java.util.*; class HashingDemo { public static void main(String[] args) { Scanner keyboard =
Here is my code: import javax.swing.*; import java.awt.*; public class PanelModel { public static
Here's my code: import java.util.Scanner; class Graph{ boolean [][]array; int N; Graph (){ array
Wen I have this code: import java.util.Scanner; import java.util.Arrays; public class Ex02 { /**
Here is the code: import javax.swing.*; import java.awt.event.*; import java.awt.*; public class TestGrid {
Here I found this code: import java.awt.*; import javax.swing.*; public class FunWithPanels extends JFrame
Here is a simple piece of code: import java.io.*; public class Read { public

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.