zoukankan      html  css  js  c++  java
  • Java小实验之数据转换

    看到有人问如图的程序,就去写了几行代码,顺便复习一下条件语句和ASCII码

     1 import java.util.Scanner;
     2 public class test1 {
     3 
     4     public static void main(String[] args) 
     5     {
     6         Scanner sc = new Scanner(System.in);
     7         System.out.print("输入一个ASCII数值:");
     8         int ascii = sc.nextInt();
     9         sc.close();
    10         char ch = (char)ascii;
    11         //在‘a’~‘z’转成‘A’~‘Z’
    12         if(ch >= 'a' && ch <= 'z')
    13         {
    14             System.out.println((char)(ch-32));
    15         }
    16         //在‘A’~‘Z’转成‘a’~‘z’
    17         else if(ch >= 'A' && ch <= 'Z')
    18         {
    19             System.out.println((char)(ch+32));
    20         }
    21         //在‘0’~‘9’输出0~9
    22         else if(ch >= '0' && ch <= '9')
    23         {
    24             System.out.println(ch);
    25         }
    26         //输出“+ - * /”
    27         else if(ch == '+' || ch== '-' || ch == '*' || ch == '/')
    28         {
    29             System.out.println("属于算术运算符");
    30         }
    31         //输出“非法字符”
    32         else
    33         {
    34             System.out.println("非法字符");
    35         }
    36     }
    37 }

    作者:耑新新,发布于  博客园

    转载请注明出处,欢迎邮件交流:zhuanxinxin@aliyun.com

  • 相关阅读:
    Andriod调试桥
    抓包工具charles的使用
    测试常用工具
    Indentation error codes
    Cmder 中文乱码的解决方法
    修改Cmder命令提示符
    统计单词出现的字数
    将字串内容输出到文件
    python数据实例str
    python语法检查工具
  • 原文地址:https://www.cnblogs.com/Arthurian/p/7745213.html
Copyright © 2011-2022 走看看