Advertisement
Guest User

Untitled

a guest
Jan 31st, 2015
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. import javax.swing.JOptionPane;
  2. public class StringInfo
  3.  
  4. {
  5.  
  6. public String sCompare = "somerandom2string3withdigits";
  7.  
  8. public StringInfo(){
  9. preDigit();
  10. JOptionPane.showMessageDialog (null, "preDigit: " + sCompare);
  11.  
  12.  
  13.  
  14. }
  15.  
  16. public int lastIndexOf(char given){
  17.  
  18. int index = -1;
  19. for (int i=0; i<sCompare.length(); i++) {
  20. char ch = sCompare.charAt(i);
  21.  
  22. if(ch == given){
  23. index = i;
  24. }
  25.  
  26.  
  27. }
  28. return index;
  29.  
  30.  
  31. }
  32.  
  33. public void preDigit(){
  34.  
  35.  
  36. for (int i=1; i<=sCompare.length(); i++) {
  37. char ch = sCompare.charAt(i);
  38.  
  39. if(Character.isDigit(ch)){
  40.  
  41. sCompare = sCompare.substring(0, i);
  42. break;
  43. }
  44.  
  45.  
  46.  
  47. }
  48.  
  49. }
  50.  
  51.  
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement