School‘s Java test

欢迎来到Cefler的博客😁

🕌博客主页:那个传说中的man的主页

🏠个人专栏:题目解析

🌎推荐文章:题目大解析(3)


目录

👉🏻第四周

素数和

cpp 复制代码
import java.util.Scanner;
public class Main {
	static public boolean IsPrime(int n)
	{
		if(n>1) {
			for(int i = 2;i<n;i++)
			{
				if(n%i==0)
					return false;
			}
			return true;
		}
		return false;
	}
	
	public static void main(String args[]) {
		int n,m;
		Scanner input = new Scanner(System.in);
		n = input.nextInt();
		m = input.nextInt();
		int[] arr = new int[m-n+1];
		//输入数据
		int sum = 0,count = 0,i=2;
		while(count<m) {
			if(IsPrime(i))
				count++;
			if(IsPrime(i)&&count>=n)
			{
				sum+=i;
			}
			
			++i;
		}
		System.out.println(sum);
	}
}

念整数

java 复制代码
import java.util.Scanner;
public class Main {
	
	public static void main(String args[]) {
		String n = new Scanner(System.in).nextLine();
		String[] str = {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
		for(int i = 0;i<n.length();i++)
		{
			int index = n.charAt(i) - '0';
			if(i==0&&n.charAt(0)=='-')
				System.out.print("fu");
			else
			{
				if(i==0)
				System.out.print(str[index]);
				else
				System.out.print(" "+str[index]);
			}
		}
		
	}
}

真心不喜欢java

相关推荐
0xDevNull10 分钟前
Java 深度解析:for 循环 vs Stream.forEach 及性能优化指南
java·开发语言·性能优化
研☆香13 分钟前
聊一聊如何分析js中的数据结构
开发语言·javascript·数据结构
博风14 分钟前
在tomcat应用里添加了一个线程池对象,向这个线程池发送任务,让其执行。 我希望在tomcat停机时,能等待线程池里的任务执行完了再停机,要如何实现?
java·tomcat
-凌凌漆-17 分钟前
【Qt】 QSerialPort::flush()介绍
开发语言·qt
徐子元竟然被占了!!20 分钟前
IS-IS协议
开发语言·网络·php
小猪皮蛋粥28 分钟前
python画图
开发语言·python
Felven28 分钟前
A. The 67th Integer Problem
开发语言
zopple31 分钟前
Laravel7.x核心特性全解析
开发语言·php·laravel
wjs202432 分钟前
MVC 应用程序
开发语言
studyForMokey32 分钟前
【Android面试】Java专题 todo
android·java·面试