上代码:
import java.util.Scannerpublic class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in)
String input = sc.nextLine()
if (input.length() == 0) {
System.out.println("输入错误")
return
}
System.out.println("汉字转unicode结果:")
char[] chars = input.toCharArray()
for (int i = 0 i < chars.length i++) {
String unicode = Integer.toHexString(chars[i])
if (unicode.length() <= 2) {
// 不足四位前面加0补齐
unicode = "00" + unicode
}
unicode = "\\u" + unicode
System.out.println(chars[i] + ": " + unicode)
}
}
}
/** * @param args */public static void main(String[] args) {
String a
Scanner in = new Scanner(System.in)
System.out.print("请输入三位数:")
a = in.nextLine()
if (isNum(a))
System.out.println("正确")
else
System.out.println("不是三位数")
}
public static boolean isNum(String str) {
//判断是否是三位数的正则表达式 ^:开头 ;[-+]?:可以含正负号0个或1个 ; //d{3}:数字类型3位 ;$:结尾
return str.matches("^[-+]?\\d{3}$")
}
注解:针对123. 131 ;aaaaa2 等非三位数都能判断
import java.applet.Appletimport java.awt.Font
import java.awt.FontMetrics
import java.awt.Graphics
import java.awt.Imagepublic class Welcome extends Applet {
int pos = 0
Image graph
int w=0
String str = "热烈欢迎2009届新生入学"
Font f = new Font("黑体", Font.BOLD, 20)
public Welcome(){
FontMetrics fm = getFontMetrics(f)
w = fm.stringWidth(str)
pos=w
}
public void paint(Graphics g) {
g.setFont(f)
g.drawString(str, pos-w, 40)
try {
Thread.sleep(100)
} catch (InterruptedException e) {
e.printStackTrace()
}
pos = pos + 5
if (pos-w >getWidth())
pos = w
repaint()
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)