Java从键盘输入一个字符,若为小写字母,则转化为大写字母;若为大写字母,则转化为小写字母;否则转化为ASCII码表中的下一个字符。

package com.haitong.homeworktwo;

import java.util.Scanner;

public class Two {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个字符:");
        char character = scanner.nextLine().charAt(0);/*取字符串的第一位*/
        int conversion = character;/*将char字符转换为int类型*/
        if ( conversion >= 65 && conversion <= 90) {
            conversion = character + 32;
            System.out.println("'"+character+"'"+"的小写字母为:"+(char) conversion);
        }else if(conversion >=97  && conversion <= 122){
            conversion = character - 32;
            System.out.println("'"+character+"'"+"的大写字母为:"+(char) conversion);
        }else {
            conversion = character + 1;
            System.out.println("'"+character+"'"+"的下一个字符为:"+(char) conversion);
        }
    }
}

你可能感兴趣的:(Java编程题,java,开发语言,ide)