Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners How to Solve the Syntax Error in java??
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


vigneshwaran
How to Solve the Syntax Error in java??
1 Answer(s)      4 years and a month ago
Posted in : Java Beginners


Syntax error in java? i have tried this program its showing error like this in Eclipse "Syntax error on token "i", VariableDeclarator expected after this token" . in last line of the program "objectname.i"

What is the reason for this error??How to access the variable "i"

import java.util.Scanner; public class constructors { int i ; private int j; private int k;

public static void main(String args[]) { System.out.println("Enter the name:");

} } class constructor{ constructors objectname = new constructors(); Scanner myScanner = new Scanner(System.in); objectname.i ; }


Advertisement
View Answers

December 2, 2010 at 10:50 AM


Hello Friend,

Actually your syntax is not correct.

Anyways, try the following code:

import java.util.*;

    class constructor{
        int i=0;
        constructor(){
        Scanner input=new Scanner(System.in);
        System.out.print("Enter number: ");
        i=input.nextInt();
        }
    }
    public class constructors{
        public static void main(String args[]){
        constructor con=new constructor();
        System.out.println(con.i);
        }
    }

Thanks



Related Tutorials/Questions & Answers:
Advertisements
 

 

 

DMCA.com