im trying to convert the int input into a string so that i can find the length of it and use the substring method. how may i go about this?
import java.util.Scanner;
public class OddEvenZero
{
public static void main(String[] args)
{
int input = 0;
int len = 0;
int currentValue = 0;
int numOdd = 0;
int numZero = 0;
int numEven = 0;
int offset = 0;
int end = 0;
Scanner scan = new Scanner(System.in);
System.out.println("Please enter an integer.");
input = scan.nextInt();
// need to convert this int (input) into a string here!!
len = input.length();
end = 1;
currentValue = input.substring(offset, end);
while (end <= len)
{
if (currentValue == 0)
{
numZero = numZero + 1;
}
else if (currentValue == 1 || currentValue == 3 || currentValue == 5 || currentValue == 7 || currentValue == 9)
{
numOdd = numOdd + 1;
}
else
{
numEven = numEven + 1;
}
offset++;
end++;
}
System.out.println("Number of zeros: " + numZero);
System.out.println("Number of even integers: " + numEven);
System.out.println("Number of odd integers: " + numOdd);
}
}