Determine if char value is in range of chars

后端 未结 2 1800
梦谈多话
梦谈多话 2021-01-27 06:55

The objective is this:

Row 1: A-L
Row 2: M-Z

Write a program that takes as input a student\'s full name (first last) and prints out the

2条回答
  •  别那么骄傲
    2021-01-27 07:50

    An easy solution would be to use the ascii value of the char.

    int m = (int)'M';
    name = name.toUpperCase();
    int initial = (int)name.charAt(0);
    
    if(initial < m)
    {
        System.out.println(" This student can sit anywhere in row 1. ");
    }
    else
    {
        System.out.println(" This student can sit anywhere in row 2. ");
    }
    

提交回复
热议问题