I'm 100% new to java. Cannot use string or "breaks" or arrays to solve the problem. Any feedback is great :)
Roadmap is:
Name the number from the user input.
Declare and initialize a counter variable to zero.
Save the right-most digit of input in a variable using the modulo operator: rightMost = input % 10
Update the value of input = input/10
Determine if the rightMost digit is odd. Use a divisibility test using the modulo operator %.
if rightMost is odd, increase the counter by 1.
if rightMost is even, do nothing.
if the input is not zero, go to step 3.
if the input is zero, the program has reached the last digit and it needs to go to step 10.
Display the results. the counter will have the value of the number of odd digits in the original number.
My code is below: (I probably haven't made it far, but I'm trying)( i likely might need to do a while or do while method)( any guide that has !, =< as a list would be appreciative)
import java.util.Scanner;
public class Labtwo
{
public static void main(String[] args)
{
System.out.print("Please enter an integer:");// program lets user know to input a number
// allow keyboard access for user
// likely in a while or do while method?
Scanner kbd = new Scanner(System.in); // allows user input labels it as kbd
int input = kbd.nextInt();// kbd new value is input as a integer
//int counter = 0;
int rightMosteven= 0;
int rightMostodd = 0;
while (input > 0){
int rightMost = (input % 10);
if(rightMost%2==0)
rightMosteven ++;
else
rightMostodd++;
input=input/10;
}
System.out.printf("Number of odd digits: "+ rightMostodd);
//System.out.printf("Number of even digits: "+ rightMosteven);
}
}
This is my new code updated im just not sure if == is considered a string if it is then my answer is 0 as stated by the "cannot use section"