java程序设计题

java程序设计题,第1张

1int year=(int)(Mathrandom()9000)+1000;

if(year%4==0&&year%100!=0){

Systemoutprintln(year+"是闰年");

}else{

Systemoutprintln(year+"是平年");

}

2Double money = 00; int x = 0;int t = 0;

if(x<100){

money = 100;

}else if(x<300){

money = 090t;

}else if(x<500){

money = 080t;

}else if(x<1000){

money = 070t;

}else{

money = 060t;

}

3对存钱这一块的东西不太了解。

4int sun = 0 , x =2 ;

while(x<1000){

sun = sum+x;

x = x+2;

}

5int x ;一个四位数

int a = x/1000;

int b = (x - a1000)/100;

int c = (x-a1000-b100)/10;

int d = x-a1000-b100-c10 ;

Sytemoutprint(d+c+b+a);

}

public class Cource{

private String cNumber;

private String cName;

private double cUnit;

public static int cTotalNum = 0;

public Cource(){

thiscName="java";

thiscNumber="123";

thiscUnit = 100;

thiscTotalNum++;

}

public String getCName() {

return cName;

}

public void setCName(String name) {

cName = name;

}

public String getCNumber() {

return cNumber;

}

public void setCNumber(String number) {

cNumber = number;

}

public double getCUnit() {

return cUnit;

}

public void setCUnit(double unit) {

cUnit = unit;

}

public void printCourceInfo(){

Systemoutprintln("cName:"+thisgetCName());

Systemoutprintln("cNumber:"+thisgetCNumber());

Systemoutprintln("cUnit:"+thisgetCUnit());

}

}

前十道

第一题

import javaio;

public class exc1 {

public static void main(String[] args) throws IOException

{

//输入正整数个数n

//使用缓冲区(BufferedReader)从文本数据流读取文本数据

InputStreamReader reader= new InputStreamReader(Systemin);

BufferedReader input=new BufferedReader(reader);

Systemoutprintln("请输入正整数个数(n):");//显示输入信息

String s=inputreadLine();//从键盘输入一个字符串10

int n=IntegerparseInt(s);//将字符串s转换为整数

//声明并初始化数组

int a[] =new int[n];

//生成包含n个两位随机正整数的数组a

for (int i=0;i<n;i++)//生成n个随机数

{

a[i]=(int)(Mathrandom()90+10);

}

//输出数组a的个元素

Systemoutprint("原始数组: ");

for(int i=0;i<n;i++)

{

Systemoutprint(a[i]+" ");

}

Systemoutprintln();

Systemoutprint("最终数组: ");

int temp;

for(int i=1;i<n;i++)

{

if(a[0]<a[i])

{

temp=a[0];

a[0]=a[i];

a[i]=temp;

}

}

for(int i=0;i<n;i++)

{

Systemoutprint(a[i]+" ");

}

}

}

第二题

import javaio;

public class exc2 {

public static void main(String[] args)

{

int sum=0;//初始时和为0

for(int i=1;i<=100;i++)//i从1到100,

{

//如果除以3余数为0,并且除以5和9,余数不为0,则加上它

if(i%3==0&&i%5!=0&&i%9!=0)

{

//Systemoutprintln(i);

sum=sum+i;

}

}

Systemoutprintln(sum);

}

}

第三题

import javaio;

public class exc3 {

public static void main(String[] arg)

{

String begin = "1";//首数字为1

String end = "23";//末数字为23

//定义s为一个字符串,初始为1

StringBuffer s = new StringBuffer(begin);

//s加上00,加上23,组成联合字符串:“10023”

sappend("00")append(end);

Systemoutprintln("可能的密码有:");

for (char i = '0'; i <= '9'; i++)

{

//将s字符串的第2个字符置为i,从0到9

ssetCharAt(1, i);

//对第二个字符置为i时,第三个字符也从0到9

for (char j = '0'; j <= '9'; j++)

{

//这样s包括了从10023到19923所有的数

ssetCharAt(2, j);

//定义密码数字pwdnumber为s转换为的整形数

int pwdnumber = IntegerparseInt(stoString());

//如果这个数字能整除57或67,输出s

if (pwdnumber % 57 == 0 || pwdnumber % 67 == 0)

{

Systemoutprintln(s);

}

}a

}

}

}

第四题

import javaio;

public class exc4 {

public static void main(String[] args) throws IOException

{

//使用缓冲区(BufferedReader)从文本数据流读取文本数据

InputStreamReader reader= new InputStreamReader(Systemin);

BufferedReader input=new BufferedReader(reader);

Systemoutprintln("请输入公里数:");//显示输入信息

String s=inputreadLine();//从键盘输入公里数

int k=IntegerparseInt(s);//将字符串s转换为整数

if (k <= 3) {

Systemoutprintln("起步价:" + 10);

} else if (k > 3 && k < 15) {

Systemoutprintln("请付" + k 2);

} else {

Systemoutprintln("请付" + ((k - 15) 3 15 + k 3));

}

}

}

第五题

import javaio;

public class exc5 {

public static void main(String[] args) {

//每一位都有1、2、3、4四种数字的可能,即从1到4

int sum=0;

for (int i = 1; i < 5; i++) {

for (int j = 1; j < 5; j++) {

for (int k = 1; k < 5; k++) {

//要求i、j、k都不相等

if (i != j && i != k && j != k) {

sum++;

Systemoutprint(i);

Systemoutprint(j);

Systemoutprint(k);

Systemoutprintln();

}

}

}

}

Systemoutprint("共能组成"+sum+"个互不相同且无重复数字的三位数。");

}

}

第六题

import javaio;

public class exc6 {

public static void main(String args[]) {

int a, b, c;//定义a、b、c为三种硬币的个数

int sum=0;//总共有多少种换法

//1分的硬币从1个到100个,最多100个

for (a = 1; a <= 100; a++) {

//2分的硬币从1个到50个,最多50个

for (b = 1; b <= 50; b++) {

//5分的硬币从1个到20个,最多20个

for (c = 1; c <= 20; c++) {

if (1a+2b+5c==100){

Systemoutprintln("1分:" + a + " " + "2分:" + b + " "+ "5分:" + c);

sum++;

}

}

}

}

Systemoutprintln("总共有 "+sum+" 种换法。");

}

}

第八题

import javaio;

public class exc8 {

public static void main(String[] args) {

for (int i = 1; i < 10; i++) {

for (int j = 0; j < 10; j++) {

for (int k = 0; k < 10; k++) {

if (iii + jjj + kkk == i100 + j10 + k) {

Systemoutprint(i);

Systemoutprint(j);

Systemoutprint(k);

Systemoutprintln();

}

}

}

}

}

}

第九题

第十题

import javaio;

public class exc10 {

public static void main(String[] args) throws IOException {

//使用缓冲区(BufferedReader)从文本数据流读取文本数据

InputStreamReader reader= new InputStreamReader(Systemin);

BufferedReader input=new BufferedReader(reader);

Systemoutprintln("请输入a:");//显示输入信息

double a=FloatparseFloat(inputreadLine());//将字符串s转换为整数

Systemoutprintln("请输入b:");//显示输入信息

double b=FloatparseFloat(inputreadLine());//将字符串s转换为整数

Systemoutprintln("请输入c:");//显示输入信息

double c=FloatparseFloat(inputreadLine());//将字符串s转换为整数

double t1,t2;

t1 = -b/2/a;

t2 = Mathpow(bb-4ac,05)/a/2;

Systemoutprint("第一个根为: ");

Systemoutprintln(t1+t2);

Systemoutprint("第二个根为: ");

Systemoutprintln(t1-t2);

}

}

第十一题

public class test { public static void main(String[] args) { int n = 0; for(int i = 1; i <= 4; ++i) for(int j = 1; j <= 4; ++j) for(int k = 1; k <= 4; ++k) if(i != j && j != k && i != k && ++n != 0) Systemoutprintln("NO"+n+":"+i+""+j+""+k); Systemoutprintln("共有:" + n + "种"); }}

不行了,累死了~~~

1、package nettest;

public class TestArray

{

int a[]={12,34,5,7,9,10};

public int max()

{

int j = a[1];

for(int i :a)

{

if(i > j)

{

j = i ;

}

}

return j;

}

public long avrage()

{

long j = 0l;

for(int i :a)

{

j = j + i;

}

return j/alength;

}

}

2、package nettest;

public class Person

{

String name;

int age;

Person(String name,int age)

{

thisname = name;

thisage = age;

}

public void printInfo()

{

Systemoutprintln("name = "+thisname+" age = "+thisage);

}

}

package nettest;

public class Student extends Person

{

String studentId;

Student(String name, int age)

{

super(name, age);

}

Student(String name, int age,String studentId)

{

super(name, age);

thisstudentId = studentId;

}

public void printInfo()

{

Systemoutprintln("name = "+thisname+" age = "+thisage+" StudentId =" + thisstudentId);

}

}

3、package nettest;

public class TestPrint

{

public static void main(String[] args)

{

for (int i = 1; i<10;i++)

{

for(int j = 0; j<i;j++)

{

Systemoutprint("");

}

Systemoutprintln();

}

}

}

public class Point {

int x;

int y;

public Point() {

}

public Point(int x, int y) {

thisx = x;

thisy = y;

}

public Point(int x) {

thisx = x;

thisy = x;

}

public double distance() {//求当前点到原点的距离

return Mathsqrt((x x + y y));

}

public double distance(int x1, int y1) {//求当前点到(x1,y1)的距离

return Mathsqrt((x-x1)(x-x1) + (y-y1) (y-y1));

}

public double distance(Point other){

int x2 = otherx;

int y2 = othery;

return Mathsqrt((x-x2)(x-x2) + (y-y2) (y-y2));

}

}

以上就是关于java程序设计题全部的内容,包括:java程序设计题、求解一道java程序设计题目(编写一个课程类Cource)、Java程序设计的几道题等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zz/9301563.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-26
下一篇2023-04-26

发表评论

登录后才能评论

评论列表(0条)

    保存