Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lessons;
- import java.util.Scanner;
- public class ReadingAChar
- {
- // program asks user if they having fun, then displays the first letter their response
- public static void main(String[] args)
- {
- Scanner keyboard = new Scanner(System.in);
- String response;
- char resp;
- int x = 0;
- System.out.println("are you having fun?");
- response = keyboard.nextLine();
- resp = response.charAt(x);
- if (resp == ' ')
- {
- x = x+1;
- resp = response.charAt(x);
- }
- else
- {
- System.out.println(resp);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement