Advertisement
Shavit

P. 12 Ex. 9.7

Dec 24th, 2013
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.58 KB | None | 0 0
  1. // Shavit Borisov
  2. // CW
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class CharChecker {
  7.  
  8.     public static void main(String[] args)
  9.    
  10.     {
  11.         Scanner in = new Scanner (System.in);
  12.        
  13.         String str;
  14.         char ch;
  15.        
  16.         System.out.print("Enter a string: ");
  17.         str = in.nextLine();
  18.        
  19.         System.out.print("Enter a character you want to check for: ");
  20.         ch = in.next().charAt(0);
  21.        
  22.         if(str.indexOf(ch) == (-1))
  23.             System.out.printf("The character '%c' doesn't appears in your string", ch);
  24.         else
  25.             System.out.printf("The character '%c' appears in your string", ch);
  26.        
  27.         in.close();
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement