输出char的Unicode值
public class E {
public static void main(String args[]) {
System.out.println((int)'你');
System.out.println((int)'我');
System.out.println((int)'他');
}
}输出α到ω的字符
public class E { |
- 求1!+2!+…+20!
public class Xiti1 { |
- 求100内的素数
public class Xiti2 { |
- 分别用do-while,for求1+1/2!+1/3!+…1/20!
class Xiti3 { |
- 1000内的完数
public class Xiti4 { |
- for求8+88+888+…前10项
public class Xiti5 { |
- 求1+2+3+…+n<8888的最大正整数n
public class Xiti6 { |
- 类与对象
//CPU.java |
- 继承/接口
//Animal.java |
//Animal.java
public interface Animal {
public abstract void cry();
public abstract String getAnimalName();
}
//Simulator.java
public class Simulator {
public void playSound(Animal animal) {
System.out.print("现在播放"+animal.getAnimalName()+"类的声音:");
animal.cry();
}
}
//Dog.java
public class Dog implements Animal {
public void cry() {
System.out.println("汪汪...汪汪");
}
public String getAnimalName() {
return "狗";
}
}
//Cat.java
public class Cat implements Animal {
public void cry() {
System.out.println("喵喵...喵喵");
}
public String getAnimalName() {
return "猫";
}
}
//Application.java
public class Example5_13 {
public static void main(String args[]) {
Simulator simulator = new Simulator();
simulator.playSound(new Dog());
simulator.playSound(new Cat());
}
}
import java.util.*;
public class E {
public static void main (String args[ ]){
Scanner reader = new Scanner(System.in);
double sum = 0;
int m = 0;
while(reader.hasNextDouble()){
double x = reader.nextDouble();
assert x< 100:"数据不合理";
m = m+1;
sum = sum+x;
}
System.out.printf("%d个数的和为%f\n",m,sum);
System.out.printf("%d个数的平均值是%f\n",m,sum/m);
}
}
public class E {
public static void main (String args[ ]) {
String s1,s2,t1="ABCDabcd";
s1=t1.toUpperCase();
s2=t1.toLowerCase();
System.out.println(s1);
System.out.println(s2);
String s3=s1.concat(s2);
System.out.println(s3);
}
}
public class E { |
import java.util.*;
public class E {
public static void main (String args[ ]) {
int year1,month1,day1,year2,month2,day2;
try{ year1=Integer.parseInt(args[0]);
month1=Integer.parseInt(args[1]);
day1=Integer.parseInt(args[2]);
year2=Integer.parseInt(args[3]);
month2=Integer.parseInt(args[4]);
day2=Integer.parseInt(args[5]);
}
catch(NumberFormatException e)
{ year1=2012;
month1=0;
day1=1;
year2=2018;
month2=0;
day2=1;
}
Calendar calendar=Calendar.getInstance();
calendar.set(year1,month1-1,day1);
long timeYear1=calendar.getTimeInMillis();
calendar.set(year2,month2-1,day2);
long timeYear2=calendar.getTimeInMillis();
long 相隔天数=Math.abs((timeYear1-timeYear2)/(1000*60*60*24));
System.out.println(""+year1+"年"+month1+"月"+day1+"日和"+
year2+"年"+month2+"月"+day2+"日相隔"+相隔天数+"天");
}
}
import java.util.*; |
public class E {
public static void main (String args[ ]) {
String str = "ab123you你是谁?";
str = str.replaceAll(regex,"\\D+");//匹配一次或多次非数字
System.out.println(str);
}
}
import java.util.*; |