- 博客(21)
- 资源 (2)
- 收藏
- 关注
原创 Java-键盘输入成绩,自定义异常类MyException用于检测输入的成绩大于100或者小于0时,抛出异常,否则就输出成绩
import java.util.Scanner;class A{ int score; public A(int score) throws Exception{ if(score<0||score>100) { throw new Exception("Error,score should be in 0-100."); } else{ this.score=score; } } void shuchu() { System.out.print.
2021-11-18 21:46:36
4834
原创 Java-定义一个描述三角形的类,根据输入的三边长,生成一个对象,最后输出周长、面积、边长
import java.util.Scanner;import java.lang.Math;class Triangle { private double a, b, c,meter,p,area; double getPerimeter() { meter=a+b+c; return meter; } void getArea() { p=meter/2; area=p*(p-a)*(p-b)*(p-c); area=Math.sqrt(area); Syste.
2021-11-18 21:42:37
1534
原创 Java-定义一个 Retangle类,有长、宽等属性,定义构造方法用来初始化类的这些属性,定义方法输出Retangle的长宽和面积。编写应用程序使用Retangle
import java.util.Scanner; class Retangle { float length,width; void jishuanarea() { float area=length*width; System.out.println("The area is:"+area); } void lenandwid() { System.out.println("The lengh is:"+length); System.out.println("The .
2021-11-18 21:41:48
2270
原创 Java-请编写一个方法实现如下功能: 输出任意三个整数 a,b,c中最大的一个,并打印出来
import java.util.Scanner;public class Main { public static void main(String args[]){ System.out.println("Please input the first number:"); System.out.println("Please input the second number:"); System.out.println("Please input the third number:".
2021-11-18 21:40:16
916
原创 Java-给出一百分制成绩,要求输出成绩等级’A’,’B’,’C’,’D’,’E’。90 分以 上 为’A’,80~89 分为’B’,70~79 分为’C’,60~69 分为’D’,60 分以下为’E
import java.util.Scanner;public class Main { public static void main(String args[]){ System.out.printf("Please input a score:\n"); Scanner in = new Scanner(System.in); int a= in.nextInt(); char x; if (a>=90) x='A'; else if (a>=80&&.
2021-11-18 21:39:16
2517
原创 Java-从键盘输入三个整数,分别存入x.y.z三个整型变量中,计算并输出三个数的和以及平均值
import java.util.Scanner;public class Main{ public static void main(String args[]){ Scanner in = new Scanner(System.in); int a = in.nextInt(); int b = in.nextInt(); int c = in.nextInt(); float sum; double aver; sum=a+b+c; aver=sum/3.0; .
2021-11-18 21:37:06
7286
原创 c:已知立方和不等式为 1^3+ 2^3+…+ m^3< n 对指定的n值,试求满足上述立方和不等式的m的整数解
#include <stdio.h>main(){ long a,b,n,sum=0; printf("Please enter n:" ); scanf("%ld",&n); for (a=1;sum<n;a++) { b=a*a*a; sum+=b; } a=a-2; printf("m<=%1d\n",a);}
2021-11-16 16:41:11
1898
3
原创 c:计算零件数有一堆零件(100--1000之间),如果分成4个零件一组的若干组,则多2个零件;如果分成7个零件一组的若干组,则多3个零件;如果分成9个零件一组的若干组,则多5个零件。编程计算满足上
#include <stdio.h>main(){ int a; for (a=100;a<=1000;a++) { if(a%4==2&&a%7==3&&a%9==5) { printf("%d\n",a); break; } }}
2021-11-16 16:40:35
6612
1
原创 c.小明今年12岁,他母亲比他大24岁。编写一个程序计算小明的母亲在几年后比小明的年龄大一倍,那时他们两人的年龄各是多少?
#include <stdio.h>main(){ int x=12, y=36, z; for (z = 1; z <= 100; z++) { if ((y+z)== 2 * (x+z)) { y+=z; x+=z; printf("year=%d\n", z); printf("mingAge=%d\n" "motherAge=.
2021-11-16 16:39:59
5181
原创 c:1.编写一个程序,求满足以下条件的最大的n:1^2 + 2^2 + 3^2 + ... + n^2 <= 1000——2.求1+1/2+1/3+...+1/100的值
1.#include <stdio.h>main(){ int a, sum = 0; for (a = 1; sum <= 1000; a++) { sum += (a * a); } a=a-2;//若无此行,当a=14时,sum>1000,再次运行a=a+1,故错误输出为15 printf("n=%d\n", a);}2.#include <stdio.h>main(){
2021-11-16 16:39:21
6967
1
原创 c——编程从键盘输入n值(10≥n≥3),然后计算并输出1的阶乘 + 2的阶乘 + … + n的阶乘
#include <stdio.h>main(){ int a, d, n, sum = 0; long b = 1; printf("Input n:"); scanf("%d", &n); for (a = 1; a <= n; a++) { for (d = 1; d <= a; d++) { b *= d; } sum += b.
2021-11-16 16:37:16
4520
2
原创 利用求阶乘函数Fact(),编程计算并输出1的阶乘+ 2的阶乘 + …+ n的阶乘的值
#include<stdio.h>long Fact(int x);int main (){ unsigned a,ret ; printf("Input n(n>0):"); scanf("%u",&a); ret=Fact(a); printf("sum = %lu\n",ret ); return 0;}long Fact(int x){ int c; long result=1,sum=0; for...
2021-11-16 16:36:04
2947
原创 编写一个程序,打印所有的“水仙花数”“水仙花数”是指一个三位数,其各位数字的立方和等于该数本身
#include <stdio.h>main(){ int a,b,c,d; for (a=1;a<=9;a++) { for(b=0;b<=9;b++) { for(c=0;c<=9;c++) { d=a*100+b*10+c; if(d==a*a*a+b*b*b+c*c*c) printf("%d\n".
2021-11-16 16:35:09
3242
原创 c语言编程——百元买百鸡问题:“公鸡5元一只;母鸡3元一只;雏鸡一元3只。百钱买百鸡,问鸡翁、母、雏各几只?”
#include <stdio.h>main(){ int a,b,c; for (a=0;a<=20;a++) { for(b=0;b<=33;b++) { c=(100-5*a-3*b)*3; if(a+b+c==100) printf("公鸡是%d只,母鸡是%d只,雏鸡是%d只.\n",a,b,c); } }}.
2021-11-16 16:28:33
18445
原创 C语言编程——韩信点兵
#include <stdio.h>main(){ int i; for (i = 6; i <= 100000; i++) { if (i % 5 == 1 && i % 6 == 5 && i % 7 == 4 && i % 11 == 10) { printf("x = %d\n", i); break; } .
2021-11-16 16:27:43
1770
原创 C语言编程计算1*2*3 + 3*4*5 + ... + 99*100*101的值
#include <stdio.h>main(){ int a,b,c,d,sum=0; for(a=1;a<=99;a+=2) { b=a+1; c=b+1; d=a*b*c; sum+=d; } printf("sum=%d",sum);}
2021-11-16 16:26:54
2067
原创 C语言编程题—穷举,抓交通肇事犯。求出车号
#include <stdio.h>main(){ int a,b,c,d; for(a=0;a<=9;++a) { for(b=0;b<=9;++b) { d=a*1000+a*100+b*10+b; for(c=1;c<=1000000;++c) { if(a!=b&&d==c*c) .
2021-10-30 21:44:39
725
原创 C语言编程题—编程打印以下图案
#include<stdio.h>main(){ int i,j,k; for(i=1;i<5;i++) { for(k=1;k<=4-i;k++) { printf("#"); } for(j=1;j<=2*i-1;j++) { printf("*"); } printf("\n")...
2021-10-30 21:40:58
4422
原创 C语言编程题—编程计算并输出1到n之间的所有数的平方与立方(循环)
#include <stdio.h>#include <math.h>main(){ int a,b,c,n; printf("Please enter n:"); scanf("%d",&n); for (a=1;a<=n;++a) { b=pow(a,2); printf("%d*%d = %d\n",a,a,b); } for (a=1;a<=n;++a) .
2021-10-30 21:37:26
4434
原创 C语言编程题—银行利息,逆推(循环)
#include <stdio.h>main(){ int n = 1; float sum = 0.0; do { sum += 1000.0; sum = sum / (1 + 12 * 0.01875 ); n++; } while (n <= 5); printf("He must save %.2f at the first year.\n", sum);}
2021-10-30 21:36:05
612
原创 C语言编程题—1+2+3+....+n(循环)
1+2+3+....+n(循环)#include <stdio.h>main(){ int a = 1, sum = 0, n; printf("Input n:"); scanf("%d", &n); do { sum += a; a++; } while (a <= n); printf("sum = %d\n", sum);}
2021-10-30 21:29:59
3869
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人