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:

  1. string number = in.nextline(); char c = number.charat(i); // position of digit want retrieve int digit = c - '0'; 
  2. if want ith digit end of integer, do:

    int digit = 0; while(i > 0) {     digit = n%10;     n /= 10;     --i; } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -