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

相关推荐
ALex_zry1 小时前
C++ ORM与数据库访问层设计:Repository模式实战
开发语言·数据库·c++
潜创微科技--高清音视频芯片方案开发7 小时前
2026年C转DP芯片方案深度分析:从适配场景到成本性能的优选指南
c语言·开发语言
Thomas.Sir7 小时前
第三章:Python3 之 字符串
开发语言·python·字符串·string
刘景贤8 小时前
C/C++开发环境
开发语言·c++
daidaidaiyu8 小时前
JMS, ActiveMQ 学习一则
java
weixin_704266058 小时前
SpringBoot全注解开发指南
java·spring boot·mybatis
星如雨グッ!(๑•̀ㅂ•́)و✧8 小时前
Webflux fromXXX对比
java
Dxy12393102169 小时前
Python 根据列表中某字段排序:从基础到进阶
开发语言·windows·python