How to Solve the Syntax Error in java??

How to Solve the Syntax Error in java??

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 ; }

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:
How to Solve the Syntax Error in java??
how to solve 'Stop Running This Script' Error ?
Advertisements
How to solve ModuleNotFoundError: No module named 'paramiko' error
How to solve ModuleNotFoundError: No module named 'paramiko' error
how to solve this kind of error in Eclipse IDE?
how to solve error like'java.lang.NumberFormatException: For input string: "7600113411"' this
How to Checking Syntax Error in PHP from Command Line
how to write and read text for javaME
How to make a connection from javaME with MySQL - SQL
ERROR 601 (42P00): Syntax error. Encountered
to solve the error - Java Beginners
How to make a connection from javaME with MySQL - SQL
How to resolve this error The filename, directory name, or volume label syntax is incorrect
sql syntax error help
how to solve
ModuleNotFoundError: No module named 'power-daps-meta-model-java-9'
ModuleNotFoundError: No module named 'power-daps-meta-model-java-9'
OCI Connectivity For Oracle Plz Solve This Error
OCI Connectivity For Oracle Plz Solve This Error
how to solve this..
how to solve this..
please solve this error Warning: mail() [function.mail]:
JavaFX issue - Java3D
Syntax error in my UPDATE..please advise
syntax error in SQL Insert Statement - Java Beginners
javadb - javadb-doc version 10.10.2.0 Maven dependency. How to use javadb-doc version 10.10.2.0 in pom.xml?
javadb - javadb-core version 10.8.1.2 Maven dependency. How to use javadb-core version 10.8.1.2 in pom.xml?
How to solve the Hibernate Common Exceptions?
syntax error in SQL Insert Statement - Java Beginners
Version of co.paralleluniverse>javafs dependency
Version of javadb>javadb dependency
how to solve an internet connection problem
Version of com.intellij>javac2 dependency
Version of javacc>javacc dependency
Solve it
Maven dependency for co.paralleluniverse - javafs version 0.1.0 is released. Learn to use javafs version 0.1.0 in Maven based Java projects
i dont no how to solve it pls
Version of javadb>javadb-client dependency
Version of javadb>javadb-common dependency
Version of javadb>javadb-core dependency
Version of javadb>javadb-dem dependency
Version of javadb>javadb-demo dependency
Version of javadb>javadb-doc dependency
Version of javadb>javadb-javadoc dependency
how to solve this problem for oracle connectivity
Maven dependency for javadb - javadb-common version 10.10.2.0 is released. Learn to use javadb-common version 10.10.2.0 in Maven based Java projects
Maven dependency for javadb - javadb-demo version 10.10.2.0 is released. Learn to use javadb-demo version 10.10.2.0 in Maven based Java projects
Maven dependency for javacc - javacc version 4.0 is released. Learn to use javacc version 4.0 in Maven based Java projects
How to fireup HTTP request from JavaFX Client
Maven Repository/Dependency: co.paralleluniverse | javafs

Ads