Advertisement
476179

reading char

Oct 8th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. package lessons;
  2. import java.util.Scanner;
  3.  
  4. public class ReadingAChar
  5. {
  6. // program asks user if they having fun, then displays the first letter their response
  7.  
  8. public static void main(String[] args)
  9. {
  10. Scanner keyboard = new Scanner(System.in);
  11. String response;
  12. char resp;
  13. int x = 0;
  14. System.out.println("are you having fun?");
  15. response = keyboard.nextLine();
  16. resp = response.charAt(x);
  17. if (resp == ' ')
  18. {
  19. x = x+1;
  20. resp = response.charAt(x);
  21. }
  22. else
  23. {
  24. System.out.println(resp);
  25. }
  26.  
  27. }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement