0

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.

Edited by happygeek: fixed formatting

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by fox07
1

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

Edited by majestic0110: n/a

0
Scanner a = new Scanner(System.in);
int s;
s=a.nextInt();
if(s % 2 == 0)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.