码迷,mamicode.com
首页 > 编程语言 > 详细

那些年,一起学的Java 2-1

时间:2015-03-13 02:02:33      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:java

/**接收用户输入的一个字符并判断其是字母还是数字,

 * 或者是其它字符,判断后输出相应的判定结果

 **/ 

import java.io.*;
public class FirstProgram 
{
	public static void main(String[] args)
	{
		char c = ‘ ‘;
		System.out.print("Enter a character please: ");
		try
		{
			c = (char)System.in.read();
		}
		catch (IOException e)
		{
			
		};
		if (c >= ‘A‘ && c <= ‘z‘ || c >= ‘a‘ && c <= ‘z‘)
			System.out.println("You‘ve entered character "+ c);
		else if (c >= ‘0‘ && c <= ‘9‘)
			System.out.println("You‘ve entered integer "+ c);
		else
			System.out.println("You‘ve entered others "+ c);

	}	
}


本文出自 “hacker” 博客,请务必保留此出处http://anglecode.blog.51cto.com/5628271/1619834

那些年,一起学的Java 2-1

标签:java

原文地址:http://anglecode.blog.51cto.com/5628271/1619834

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!