Java入门基础(锐格实验4)

Posted 晨沉宸辰

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java入门基础(锐格实验4)相关的知识,希望对你有一定的参考价值。

在这里插入图片描述

import java.util.*;
public class Main {

    public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in =new Scanner(System.in);
		String now=in.next();
		String del=in.next();
		now=now.replace(del,"");
		System.out.println(now);
		reverse(now);
	}

private static void reverse(String str) {
	if(str.length()==1) {
		System.out.println(str);
	}
	else {
		String s1=str.substring(0,str.length()-1);
		String s2=str.substring(str.length()-1);
		System.out.print(s2);
		reverse(s1);
	}
	}
}

在这里插入图片描述

import java.util.*;
public class Main {

    public static void main(String[] args) {
		// TODO Auto-generated method stub
		String a;
		Scanner in=new Scanner(System.in);
		a=in.next();
		ArrayList<String>b=new ArrayList<String>();
		while(!a.equals("end")) {
			b.add(a);
			a=in.next();
		}
		Collections.sort(b);
		for(int i=0;i<b.size();i++) {
			System.out.print(b.get(i)+" ");
		}
	}
}

在这里插入图片描述

import java.util.*;
public class Main {

    public static void main(String[] args) {
		// TODO Auto-generated method stub
		String a,b;
		HashSet<String>c=new HashSet<String>();
		HashSet<String>java=new HashSet<String>();
		Scanner in=new Scanner(System.in);
		a=in.next();
		while(!a.equals("end")) {
			c.add(a);
			a=in.next();
		}
		b=in.next();
		while(!b.equals("end")) {
			java.add(b);
			b=in.next();
		}
		c.retainAll(java);
		Iterator<String>iter=c.iterator();
		while(iter.hasNext()) {
			String cm=iter.next();
			System.out.print(cm+" ");
		}
		}
}

在这里插入图片描述

import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    	// TODO Auto-generated method stub
		HashMap<String,Integer > map=new HashMap<String, Integer>();
		int n;
		Scanner reader = new Scanner(System.in);
		n = reader.nextInt();
		for(int i=0;i<n;i++) {
			map.put(reader.next(), reader.nextInt());
		}
		System.out.println(map.get(reader.next()));
		Object[] key =  map.keySet().toArray();    
		Arrays.sort(key);    
		  
		for(int i = 0; i<key.length; i++)  
		{    
		     System.out.println(key[i]+"="+map.get(key[i]));    
		}  
	}

}

在这里插入图片描述

import java.util.*;
import java.math.*;
public class Main {

 public static void main(String[] args)
 {
    Scanner in =new Scanner(System.in);
	BigInteger n=new BigInteger("0");
 	n=in.nextBigInteger();
	BigInteger i=new BigInteger("1");
	BigInteger ONE=new BigInteger("1");
 	BigInteger ZERO=new BigInteger("0");
 	BigInteger result=new BigInteger("0");
	 BigInteger n2=new BigInteger("1");
	 for( i=ONE;i.compareTo(n)<=0;i=i.add(ONE)){
 		BigInteger n1=new BigInteger("1");
 		for( n2=ONE;n2.compareTo(i)<=0;n2=n2.add(ONE)){
		 n1=n1.multiply(n2);
	 	}
 	result=result.add(n1);
	 }
  System.out.println(result);
 }
  
}
   

在这里插入图片描述

import java.util.*;
import java.math.*;
public class Main{
public static void main(String[] args)
 {
    Calendar calendar =Calendar.getInstance();
 	String regex="\\\\D+";
	Scanner reader=new Scanner(System.in);
 	String str=reader.nextLine();
	String digitWord[]=str.split(regex);
	int x,y,z;
	x=Integer.parseInt(digitWord[0]);
	y=Integer.parseInt(digitWord[1]);
	z=Integer.parseInt(digitWord[2]);
	calendar.set(2019,6,12);
 	long timeone=calendar.getTimeInMillis();
	calendar.set(x,y-1,z);
 	long timetwo=calendar.getTimeInMillis();
	long xc=(timeone-timetwo)/(1000*60*60*24);
 	System.out.println(xc);
    }
}
    

在这里插入图片描述

import java.util.*;
public class  Main {

    public static void main(String[] args) {
    	// TODO Auto-generated method stub
		Calendar calendar=Calendar.getInstance();
		String regex="\\\\D+";
		Scanner reader=new Scanner(System.in);
		String a=reader.nextLine();
		reader.close();
		String digit[]=a.split(regex);
		int x,y;
		x=Integer.parseInt(digit[0]);
		y=Integer.parseInt(digit[1]);
		calendar.set(x, y-1, 1);
		int wday=calendar.get(Calendar.DAY_OF_WEEK)-1;
		int mday;
		int ey=28;
		if(x%400==0||(x%100!=0&&x%4==0)){
			ey=29;
			if(y==1||y==3||y==5||y==7||y==8||y==10||y==12) {
				mday=31;
			}
			else if(y==4||y==6||y==9||y==11) {
				mday=30;
			}
			else
				mday=ey;
		}
		else 
		 {
			ey=28;
			if(y==1||y==3||y==5||y==7||y==8||y==10||y==12) {
				mday=31;
			}
			else if(y==4||y==6||y==9||y==11) {
				mday=30;
			}
			else
				mday=ey;
		}
		String b[]=new String[wday+mday];
		for(int i=0;i<wday;i++) {
			b[i]="";
		}
		for(int i=wday,n=1;i<(wday+mday);i++) {
			b[i]=String.valueOf(n);
			n++;
		}
		for(int i=0;i<b.length;i++) {
			if(i%7==0&&i!=0) {
				System.out.printf("\\n");
			}
			System.out.printf("%5s",b[i]);
		}
    }
}

以上是关于Java入门基础(锐格实验4)的主要内容,如果未能解决你的问题,请参考以下文章

Java入门基础(锐格实验5)

Java入门基础(锐格实验6)

Java实验题3_4_林大锐格平台

Java实验题3_7_林大锐格平台

Java实验题3_1_林大锐格平台

Java实验题3_3_林大锐格平台