wiley_pastebin

lesson 4 errors 2

Mar 15th, 2019
2,262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.45 KB | None | 0 0
  1. public class ExceptionDemo {
  2.  public static void highlightTheI(String in) {
  3.   // The integer below could be equal to minus one
  4.   int x = in.indexOf('i');
  5.  
  6.   if(x >= 0) {
  7.    System.out.println(in.substring(0, x) + 'I' +               
  8.                       in.substring(x+1));
  9.   } else {
  10.   System.out.println("There is no i in " + in);
  11.  }
  12. }
  13.  
  14.   public static void main(String[] args) {
  15.    String randomWord = "team";
  16.    highlightTheI(randomWord);
  17.  }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment