标签:stat pre new product math img lan rgs out
实验源码:
import java.lang.Math;
class Narcissus{
public static void main(String[] args){
int num1,num2,num3;
int count = 0;
for(int i = 100;i < 1000;i++){
num1 = i / 100;
num2 = (i % 100) / 10;
num3 = i % 10;
if(Math.pow(num1,3)+Math.pow(num2,3)+Math.pow(num3,3) == i){
count = 1;
System.out.println(i+"是水仙花数");
}
}
if(count == 0){
System.out.print("No");
}
System.out.println();
}
}
实验结果:
实验源码:
class Staggered{
public static void main(String[] args){
int num = 13;
int flag = 1;
int sum = 0;
for(int i = 0;i <= 99;i++){
sum += flag * num;
flag = -flag;
num += 10;
}
System.out.println(sum);
}
}
实验结果:
实验源码:
class Factorial{
public static void main(String[] args){
long result = 0;
for(int i = 1;i <= 20;i++){
long product = 1;
for(int j = 1;j <= i;j++){
product *= j;
}
result += product;
}
System.out.println("1!+2!+3!+…+20! = "+result);
}
}
实验结果:
实验源码:
class Summation{
public static void main(String[] args){
String num = "";
long sum = 0;
for(int i = 1;i <= 10;i++){//求前N项的和
num +='8';
sum += Long.parseLong(num);
}
System.out.println(sum);
}
}
实验结果:
实验源码:
class Perfect{
public static void main(String[] args){
for(int i = 1;i < 1000;i++){
if(i == 1){
continue;
}
int sum = 1;
for(int j = 2;j < i;j++){
if(i % j == 0){
sum += j;
}
}
if(sum == i){
System.out.println(i + "是一个完数");
}
}
}
}
实验结果:
实验源码:
class Simple{
public static void main(String[] args){
int sum = 0;
int i = 1;
while(sum < 8888){
sum += i;
i++;
}
System.out.println("满足1+2+3+…+n<8888的最大正整数为"+i);
}
}
实验结果:
实验源码:
import java.util.Scanner;
class Triangle {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();// 三角形的层数
String op = sc.next();// 三角形的符号
for (int i = 1; i <= N; i++) {
int k = 1;
for (int j = 1; j <= 2 * N; j++) {
if (j == N - i + k) {
System.out.print(op);
k++;
}
if (j == N) {
System.out.println();
break;
} else {
System.out.print(" ");
}
}
}
}
}
实验结果:
题目较为基础,比较简单
标签:stat pre new product math img lan rgs out
原文地址:https://www.cnblogs.com/lmcmha/p/11483721.html