String s = "350424198705062023"
int leh = s.length()
System.out.println(s.length())
if (leh != 18 &&leh != 15) {
System.out.println("NO")
}
else {
if (leh == 18) {
int se = Integer.valueOf(s.substring(leh - 1)) % 2
String dates = s.substring(6, 10) + "-" + s.substring(10, 12) + "-" + s.substring(12, 14)
System.out.println(dates)
String sex = ""
if (leh == 0) {
sex = "M"
}
else {
sex = "F"
}
System.out.println(sex + "\t" + dates)
}
else {
String dates = "19" + s.substring(6, 8) + "-" + s.substring(8, 10) + "-" + s.substring(10, 12)
System.out.println(dates)
}
}
}
从控制台接收一个字符,然后将其打印出来public static void main(String [] args) throws IOException{
System.out.print(“Enter a Char:”)
char i = (char) System.in.read()
System.out.println(“your char is :”+i)
}
}
从键盘输入其它类型数据:
public static void main(String [] args) {
Scanner sc = new Scanner(System.in)
System.out.println(“请输入你的姓名:”)
String name = sc.nextLine() //字符串
System.out.println(“请输入你的年龄:”)
int age = sc.nextInt() //整数
System.out.println(“请输入你的工资:”)
float salary = sc.nextFloat() //浮点数
System.out.println(“你的信息如下:”)
System.out.println(“姓名:”+name+“\n”+“年龄:”+age+“\n”+“工资:”+salary)
}