java - How to use something like the charAt for integers -
i trying make program uses 3 digit numbers identify items , trying use charat method integers or something. im not sure. im beginner , apologize need help. need bit of use if statement , relational operators. im trying if last digit in number less 5 {item} , if greater 5 {item}. that. thank in advance.
string number; system.out.println("enter 3 digit number: "); number = in.nextline(); switch (number.charat(0)) { //stuff } if (number > 5) { //it item { else { //it other item {
there @ least 2 ways can it:
string number = in.nextline(); char c = number.charat(i); // position of digit want retrieve int digit = c - '0';
if want ith digit end of integer, do:
int digit = 0; while(i > 0) { digit = n%10; n /= 10; --i; }
Comments
Post a Comment