-5

Hey i am a beginner in java and am getting the error at line 11. I am not sure why am getting this error Here's the code

package practice;
import java.util.Scanner;

public class VariablesDemo {

int empid;
char gender;
float allowance;
double basicSalary;
Scanner src = new Scanner(System.in);
System.out.println("Enter the Employee id");
public void setEmployeeId(int empid)
{
    System.out.println("Enter the Employee id");
    this.empid= src.nextInt();
}
public void setEmployeeGender(char gender)
{
    System.out.println("Enter the Employee gender");
    String gender_type=src.next(); 
    this.gender= gender_type.charAt(0);
}
public void setEmployeeAllowance(float allowance)
{
    System.out.println("Enter the Employee allowance");
    this.allowance= src.nextFloat();
}
public void setEmployeeBasicSalary(double basicSalary)
{
    System.out.println("Enter the Employee basic Salary");
    this.basicSalary= src.nextDouble();
}
}
Joan
  • 427
  • 3
  • 6
  • Remove line 11 altogether, you already have it in the `setEmployeeId` method. – maksimov Apr 15 '13 at 12:43
  • 2
    this is wrong , this is not only the place for experts like you val , but for beginners also , what right you have to ask him to down his question !! – anshulkatta Apr 15 '13 at 12:43
  • 6
    @Val OP said he's a begginer, he's here to learn, not to get abuse. – maksimov Apr 15 '13 at 12:44
  • 2
    Beginners should start writing small programs and learn debugging, which also means minimizing their code. I see an opposite tendency. Many users do not understand what "good question" means. It means that that SO must not be turned into a dump of garbage. – Val Apr 15 '13 at 12:51
  • @Val It was jst trail and error stuff i was doing while learning java and i cam up with the problem which i didn't understood. I am using Stackoverflow for the 1st time so didn't knew how to post the stuff.If u get irritated by reading such long and useless code than i request you that please dnt help not at least a beginner bcoz most of thm vl post such shit!!! – user1852501 Apr 15 '13 at 13:15
  • 1
    You should not be an experienced SO user to understand that posting unrelated stuff is bad thing. Debugging process should tell you what is related and what is not. Localizing the bug = determining what is related to the error and what is not. – Val Apr 15 '13 at 13:24

7 Answers7

2
System.out.println("Enter the Employee id"); 

should be inside any method.

If you still want to write SOP outside of the method then refer this Question

Community
  • 1
  • 1
AmitG
  • 10,365
  • 5
  • 31
  • 52
2

only System.out.println() should be in any method because its a method call....

Scanner src=new Scanner(System.in); can be outside the method in class anywhere..!!

anshulkatta
  • 2,044
  • 22
  • 30
2

As a beginner, you should first try to master the basics of the language, like how to define a class, an attribute, or a method. Use a reference book, or a good tutorial to get started.

Good luck!!

Lahniep
  • 719
  • 1
  • 11
  • 30
2
    System.out.println("Enter the Employee id"); 

That line should be in a method. There only variable initzalization, blocks or declaration are allowed.

Read this, it will help you a lot!

http://www.loirak.com/prog/java.php

http://docs.oracle.com/javase/tutorial/

Mueretee
  • 550
  • 2
  • 4
  • 16
1
System.out.println("Enter the Employee id"); 

this line are executable line for printing this should be written in method only

Only initialization and declaration are allowed outside method

Pratik
  • 30,639
  • 18
  • 84
  • 159
1

Execution statements must be inside method.

System.out.println("Enter the Employee id");

Above line should be in the method. Not in the class directly.

only variable initialization, declaration, static blocks, init blocks are allowed outside the method. I would suggest to read basic java tutorials first before trying your hands in java coding.

Jaydeep Rajput
  • 3,605
  • 17
  • 35
0

System.out.println("Enter the Employee id");

is a call to the method println() and thus it mustn't be among variable declarations...

MikO
  • 18,243
  • 12
  • 77
  • 109