全国高校计算机能力挑战赛Java试题
程序员文章站
2024-01-01 16:42:28
1.输入个数N,求出1-N之间所有立方数package zzhaosheng;import java.util.Scanner;public class jisuanlifangshu {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.println("请输入一个N数,计算0-N之间的立方数的个数");int N = sc.nextInt();int nu...
1.输入个数N,求出1-N之间所有立方数
package zzhaosheng;
import java.util.Scanner;
public class jisuanlifangshu {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个N数,计算0-N之间的立方数的个数");
int N = sc.nextInt();
int num=0;
for(int i=2;i<N;i++) {
for(int j=1;j<(i/2);j++) {
if((i/j)/j==j&&(i/j)%j==0&&i%j==0) {
num+=1;
//System.out.println(i);
break;
}
}
}
System.out.println(1+num);
}
}
2.输入N M两个数 输出两个数之间所有非偶数的合数
package zzhaosheng;
import java.util.Scanner;
public class jisuanN_Mheshu {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("输入一个N 输入一个M 输出这两个数之间所有合数");
int N = scanner.nextInt();
int M = scanner.nextInt();
int num=0;
for(;N<M;N++) {
for (int i=2;i<N/2;i++) {
if (N%i==0&&N%2!=0) {
num+=1;
break;
}
}
}
System.out.println(num);
}
}
3.输入一个字符串,判断a-z个数 0-9个数 其他符号个数
package zzhaosheng;
import java.io.BufferedReader;
import java.util.Scanner;
public class tongjiString {
public static void main(String[] args) {
System.out.println("输入一个字符串,判断a-z个数 0-9个数 其他符号个数");
Scanner scanner = new Scanner(System.in);
String string = scanner.nextLine();
//System.out.println(string);
char[] chs = string.toCharArray();
int str_num=0;
int numb_num=0;
int other_num=0;
int kg_num=0;
for(int i=0;i<chs.length;i++) {
//System.out.println(chs[i]);
if((chs[i]>='a'&&chs[i]<='z')||(chs[i]>='A'&&chs[i]<='Z')) {
str_num+=1;
}else if(chs[i]>='0'&&chs[i]<='9') {
numb_num+=1;
} else if(chs[i]==' ') {
kg_num+=1;
}else{
other_num+=1;
}
}
System.out.println("a-z"+" "+str_num);
System.out.println("0-9"+" "+numb_num);
System.out.println("空格"+' '+kg_num);
System.out.println("other"+" "+other_num);
}
}
本文地址:https://blog.csdn.net/weixin_44976835/article/details/109988257