1.
3.
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);
}
}
2.
public class E{
public static void main(String args[]){
String s="ABCDabcd";
char cStart=s.charAt(0);
char cEnd=s.charAt(s.length()-1);
System.out.println(cStart);
System.out.println(cEnd);
}
}
3.
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+"日相隔"+"相隔天数"+"天");
}
}
4.
import java.util.*;
public class E{
public static void main(String args[]){
double a=0,b=0,c=0;
a=12;
b=24;
c=Math.asin(0.56);
System.out.println(c);
c=Math.cos(3.14);
System.out.println(c);
c=Math.exp(1);
System.out.println(c);
c=Math.log(8);
System.out.println(c);
}
}
5.
public class E{
public static void main(String args[]){
String str="ab123you你是谁?";
String regex="\\D+";
str=str.replaceAll(regex,"");
System.out.println(str);
}
}
6.
import java.util.*;
public class E{
public static void main(String args[]){
String cost="数学87分,物理76分,英语96分";
Scanner scanner=new Scanner(cost);
scanner.useDelimiter("[^0123456789.]+");
double sum=0;
int count=0;
while(scanner.hasNext()){
try{ double score=scanner.nextDouble();
count++;
sum=sum+score;
System.out.println(score);
}
catch(InputMismatchException exp){
String t=scanner.next();
}
}
System.out.println("总分:"+sum+"分");
System.out.println("平均分:"+sum/count+"分");
}
}