plz help on java am still a novice

+1 OJO OLAMIDE JEREMIAH · November 8, 2015
plz help me with this it showing syntax error at
double mide;
public class howtodeclearvariable {
   double mide;
   mide = 5.67;
    public static void main(String[] args) {
        System.out.print("i need");



Post a Reply


Oldest  Newest  Rating
0 Jon Z. · November 8, 2015
double mide = 5.67;
0 jack barnes · November 9, 2015
I'm pretty sure the problem is that you're not declaring your variable(s) inside of your main method.
public class blah{
public static void main(String args[]){
int num = 4;
0 OJO OLAMIDE JEREMIAH · December 9, 2015
plz how do i get input from user ...........
0 Jon Z. · December 11, 2015
you can use a Scanner. google it.
0 Gary Whitney · December 12, 2015
1. How to declare.
a. Get in the habit of making your class names  begin with a Capital letter and use camelCase while you at it e. g. HowTodDeclareVariable
b. You can declare variables outside the main method  and you can assign them a value at the declaration BUT you are trying to declare it an then access it.
this works: double mide =5.67;
c.  If you try to use a non static variable inside a static method i.e. main you will get a different error unless you make the variable static e.g public static double mide =5.67;
 this has to do with the fact that a class is a blueprint to make an object so anything you put inside it stays with the Class.
d. As Jack suggested you could and probably should declare your variable inside the main method unless you have a good reason for wanting all objects made from the class to share the same variable.

2. Using Scanner
Let me just warn you that Scanner doesn't do any validation and it blocks the program from continuing until the enter key is pressed.
The has and hasNext methods are the key to getting types of input.
Best Google how to use it and then try putting in the wrong data types.
  • 1

Java / Android Development


Very popular language used to create desktop applications, website applets, and Android apps.

Bucky Roberts Administrator