I don't know how to show odd or even digits from an integer number. For example I ask the user to enter a 4 digits integer number. For example the user enter 4875. I want to display odd digits (7 5) and even digits (4 8). By Extract each digit of the number using integer division and store the results in separate variables.
for example, that 4875 is 4*1000+8*100+7*10+5
Be creative, for example if you read input from user you will get string object. Convert string to character array, read array element by element, convert element to integer and fine out if it is odd or even number.
rest = n%10;//ghet the last digit of the number
n=(n-rest)/10; //the number gets the last digit out
//see what we got
//after you have the variables you can test if(variable%2==0) is odd else its even
Good luck, reminds me of my first year of Computer Science (i was coding this problem in C) :)
Can someone please tell me why I have been down-voted for previous post? I really wanted to solution this problem. I am used to explaint a lot of students facts like this so that's why I gave ki72 the answer! If I would have bad manners fo course I should have been down-voted.
I really don't understand. Someone please tell me. And maybe don't down-vote this post, too. Really. No disrespect intended.
public class GrossmontBank
//class variables (global - accessible throughout this class)
//scanner object to be used throughout
private static Scanner input = new Scanner(System.in);