16秋计算机JAVA第五节课作业

1.
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+"分");
	}
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值