-1

I'm a beginner at Java and I'm creating a program that stores the names and weight of students in two different arrays after taking input from the user 30 times. Here's my code:

import java.util.Scanner;
public class bodymass {

    public static void  main(String[] args) {

        Scanner scan=new Scanner(System.in);
        String[] studentName= new String[30];
        System.out.println("Please enter the Names of 30 students");
        // This "i" is your counter.
        for (int i=0; i< studentName.length; i++) {
            studentName[i]= scan.nextLine();}
        System.out.println("Please enter the Weight of 30 students");
        Scanner scan1= new Scanner(System.in);
        int[] studentWeight= new int[30];
        for(int i=0; i<studentWeight.length; i++) {
            studentWeight[i]= scan.nextInt();}
        }

    }

However when I debug it, I get the message:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: at bodymass.main(bodymass.java:5)

What does it mean? I would be grateful if somebody guides me through this.

ggorlen
  • 33,459
  • 6
  • 59
  • 67
  • Compiled fine for me. – mypetlion Aug 17 '18 at 16:35
  • Did you edit your code? It's fine now... – Ben Holland Aug 17 '18 at 16:37
  • I edited the code but it's been fine all along. I didn't add or remove any braces. I've not seen that compilation error before though. Maybe: https://stackoverflow.com/questions/1124788/java-unresolved-compilation-problem – ggorlen Aug 17 '18 at 16:39
  • Try naming the class something like "BodyMass" instead of "bodymass", you may have some lint checks that are upset with the non-standard naming of your class. – Ben Holland Aug 17 '18 at 16:43
  • you could have some hidden characters in different encoding at line #5 . try manually deleting that line. This happens if you copy the code for somewhere and its in different encoding – NullPointerException Aug 17 '18 at 17:38

1 Answers1

-1

I have tried it for 2 students and ensure that your java class having no errors.

package com.test.practice;

import java.util.Scanner;

public class Bodymass {

public static void main(String[] args) {
     Scanner scan=new Scanner(System.in);
        String[] studentName= new String[2];
        System.out.println("Please enter the Names of 2 students");
        // This "i" is your counter.
        for (int i=0; i< studentName.length; i++) {
           System.out.print("Enter the student name at postion "+i+". "); 
           studentName[i]= scan.nextLine();
        }

        System.out.println("Please enter the Weight of 2 students");
        Scanner scan1= new Scanner(System.in);
        int[] studentWeight= new int[2];

        for(int i=0; i<studentWeight.length; i++) {
            System.out.print("weight of student at position "+i+" "); 
            studentWeight[i]= scan.nextInt();
            }
    }
}
Roshini
  • 100
  • 1
  • 8