Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package class170629;
- import java.util.Scanner;
- public class arrays02 {
- public static void main(String[] args) {
- /*
- * Exercise 2, slide 28
- * input : 10 chars to an array
- * output: the keys of the upper case letters
- */
- // create a scanner
- Scanner s = new Scanner(System.in);
- // define an integer array, size=10
- char[] chars = new char[10];
- System.out.printf("Enter %d chars:\n", chars.length);
- // get data from user and save it in the array
- for (int i = 0; i < chars.length; i += 1) {
- chars[i] = s.next().charAt(0);
- }
- s.close();
- // scan the chars atrray
- for (int i = 0; i < chars.length; i += 1) {
- // if upper case
- if (chars[i] >= 'A' && chars[i] <= 'Z') {
- // print character
- System.out.printf("Upercase letter (%c) at position %d\n",
- chars[i], i);
- }
- System.out.println();
- }
- }
- }
Add Comment
Please, Sign In to add comment