Trouble with method and switch statement

This program is supposed to evaluate each digit in a number input from the user. For example,

user inputs: 2003

it would find 3 even numbers (0 is considered even), 1 odd number, 2 non-zero numbers, and 2 zeros.

I keep getting the errors:

symbol : method hasNext()

location: class java.lang.String

while (integer.hasNext())

incompatible types

found: java.lang.String

required: int

switch (integer)

and this is my code:

import java.util.Scanner;

import java.lang.String;

import java.io.*;

public class Project5B1

{

public static void main(String[] args)

{

System.out.print ("Enter an integer: ");

Scanner scan = new Scanner (System.in);

String integer = scan.next();

int odd = 0;

int even = 0;

while (integer.hasNext())

{

switch (integer)

{

case '0':

even = even + 1;

case '1':

odd = odd + 1;

case '2':

even = even + 1;

case '3':

odd = odd + 1;

}

}

System.out.println ("Number of odd digits: " + odd);

System.out.println ("Number of even digits: " + even);

}

}

It's not finished yet but I wanted to make sure I had the format right before I added the specifics. And it's not so any help would be great. Thanks!

[1379 byte] By [cherbearaua] at [2007-10-2 14:01:25]
# 1

Your code has several errors. First, the line:

while (integer.hasNext())

is wrong because integer is a String and the String class does not have a hasNext() method.

Second, the line:

switch (integer)

is wrong because only ints or enumerated constants are allowed in a switch statement and integer (despite its name) is a String not an int.

Gita_Weinera at 2007-7-13 12:08:33 > top of Java-index,Java Essentials,Java Programming...