hi: i'm trying to make a simple java program which can determine whether a number is odd or even. I am 100% Completly new to java and just started, and so I do not understand most terms and such, so my apologies for that.

The Following code is wht i have got so far:

import java.util.*;
/**
* AWT Sample application
*
* @author
* @version 1.00 09/09/07
*/
public class Oddeven {



public static void main(String[] args) {
s = new Scanner(System.in);
int a
if(a % 2 == 0)
System.out.println("even");
else
System.out.println("odd");
}
}

and the error i got was:

java:12: cannot find symbol
symbol  : variable s
location: class Oddeven
s = new Scanner(System.in);
^

Please help explain to me how to resolve my problem is a newbie friendly terms as possible..thanks again so much in advance.

Recommended Answers

All 2 Replies

Hi runee1000, welcome to the forums. Please could you use code tags

for code, it just makes it much easier to read.

import java.util.*;
/**
* AWT Sample application
*
* @author
* @version 1.00 09/09/07
*/
public class Oddeven {


public static void main(String[] args) {
    s = new Scanner(System.in);
    int a
    if(a % 2 == 0)
       System.out.println("even");
    else
       System.out.println("odd");
}
}

on line 12, you are initializing the variable "s" but you have not declared a TYPE for this variable. The TYPE of this variable needs to be the classname you are instantiating. I.e. you are using the Scanner class. So line 12 must be changed to:

Scanner s = new Scanner(System.in);

You also need to assign the user input to the variable a, but I'll let you try figure that out for yourself!
I hope this helps, if you have any questions about this, feel free to ask here or look here : http://www.java-made-easy.com/java-scanner.html

Scanner a = new Scanner(System.in);
int s;
s=a.nextInt();
if(s % 2 == 0)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.