「大一java程序设计习题」java程序设计考题

博主:adminadmin 2022-12-03 07:57:08 63

今天给各位分享大一java程序设计习题的知识,其中也会对java程序设计考题进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

帮忙做一个Java程序设计题

//接口

public interface Shape{

    public abstract double getPeremeter();

    public abstract double getArea();

}

//矩形类

public class MyRect implements Shape{

    private double width = 0; //宽

    private double height = 0;//长

    private double arc = 0;//对角线

    public MyRect(double width, double height){

        this.width = width;

        this.height = height;

    }

    

    @Override

    public double getPeremeter(){

        return (width + height) * 2;

    }

    

    @Override

    public double getArea(){

        return width * height;

    }

    

    public void show(){

        arc = Math.sqrt((width * width) + (height * height))

        System.out.println("长:"+ height + " 宽:" + width + " 面积:" + getArea() + " 对角线:" + arc);

    }

    

}

public class test{

    public static void main(String [] args){

        MyRect myRect = new MyRect(20, 30);

        System.out.println("周长:" + myRect.getPeremeter());

        System.out.println("面积:" + myRect.getArea());

        myRect.show();

    }

}

大一编程入门java,这道题怎么做呢?

========汽车Auto类========================

package com.cn.answer;

/**

* 这是汽车类 Auto

* @Title: Auto.java

* @Description:

* @author

* @date 2020-06-10 09:51:08

*/

public class Auto {

public double speed;

public void start(){

System.out.println("这是启动的方法start");

}

public void speedUp(){

System.out.println("这是加速的方法speedUp");

}

public void stop(){

System.out.println("这是停止的方法stop");

}

public double getSpeed() {

return speed;

}

public void setSpeed(double speed) {

this.speed = speed;

}

@Override

public String toString() {

return "Auto [speed=" + speed + "]";

}

}

===========================================

=============这是Auto的子类Bus类===========

package com.cn.answer;

/**

* 这是Auto的子类Bus类

* @Title: Bus.java

* @Description:

* @author 二娃子

* @date 2020-06-10 09:55:01

*/

public class Bus extends Auto {

private int passenger;

public Bus(int passenger) {

super();

this.passenger = passenger;

}

public int getPassenger() {

return passenger;

}

public void setPassenger(int passenger) {

this.passenger = passenger;

}

/**

* 这是乘客上车的方法

* @param passenterNum 乘客上车的人数

* @return

*/

public int gotOn(int passenterNum){

this.passenger+=passenterNum;

return passenger;

}

/**

* 这是乘客下车的方法

* @param passenterNum 乘客下车的人数

* @return

*/

public int gotOff(int passenterNum){

this.passenger-=passenterNum;

return passenger;

}

}

=============这是Auto的子类Bus类 结束===========

==========测试类=====================

/**

* 这是Bus的测试类

* @Title: BusTest.java

* @Description:

* @author 二娃子

* @date 2020-06-10 09:58:08

*/

public class BusTest {

public static void main(String[] args) {

//创建Bus类,设置一个初始化的乘客人数(这里比如是10人)

Bus bus = new Bus(10);

//测试上车的人数

int passenger = bus.gotOn(5);

//输出现在车上的人数

System.out.println(passenger);

//测试下车的人数

int passenger2 = bus.gotOff(10);

//输出现在车上的人数

System.out.println(passenger2);

}

}

==============测试类结束==========

大一Java程序设计问题

import java.util.Calendar;

import java.util.Scanner;

import java.util.regex.Matcher;

import java.util.regex.Pattern;

/**

 *

 * @(#) A.java

 * @Package 

 * 

 * Copyright © GTA Corporation. All rights reserved.

 *

 */

public class A {

public static void main(String[] args) {

try {

cla();

} catch (ILLegalYearException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (ILLegalSalaryException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

public static double cla()  throws ILLegalYearException, ILLegalSalaryException{

Scanner sc = new Scanner(System.in);

System.out.println("请输入员工入职年份:");

String year = sc.next();

System.out.println("请输入员工工资:");

String num = sc.next();

Pattern pattern = Pattern.compile("[0-9]*"); 

Matcher isNum = pattern.matcher(year);

if( !isNum.matches() ){

throw new ILLegalYearException("无效入职年份");

}

int yearInt = Integer.parseInt(year);

int numInt = Integer.parseInt(num);

int date = Calendar.getInstance().get(Calendar.YEAR);;

if(yearInt  0 || yearInt  date){

throw new ILLegalYearException("无效入职年份");

}

if(numInt  500){

throw new ILLegalSalaryException("无效月工资");

}

int cha = date - yearInt;

double count = 0;

if(cha  1){

count = numInt;

}else if(cha  3){

count = numInt * 1.3;

}else if(cha  5){

count = numInt * 1.5;

}else{

count = numInt * 2;

}

return count;

}

}

/*自定义异常*/  

class ILLegalYearException extends Exception  

{  

    public ILLegalYearException(String msg)  

    {  

        super(msg);  

    }  

}   

  

class ILLegalSalaryException extends Exception  

{  

    public ILLegalSalaryException(String msg)  

    {  

        super(msg);  

    }  

}

JAVA程序面向对象程序设计20道题

1.D

正确接口应该是:

public boolean renameTo(File dest)重新命名此抽象路径名表示的文件

2.B,D

3.A

4. B

5. D

参见管道的 API

public abstract class Pipeextends Object

实现单向管道传送的通道对。

管道由一对通道组成:一个可写入的 sink 通道和一个可读取的 source 通道。一旦将某些字节写入接收器

通道,就可以按照与写入时完全相同的顺序从源通道中读取这些字节。

在另一个线程从管道中读取这些字节或先前已写入的字节之前,是否阻塞将该字节写入管道的线程是与系

统相关的,因此是未指定的。很多管道实现都对接收器和源通道之间一定数量的字节进行缓冲,但是不应

假定会进行这种缓冲。

6.A

参见 API

InputStreamReader 是字节流通向字符流的桥梁:它使用指定的 charset 读取字节并将其解码为字符。它

使用的字符集可以由名称指定或显式给定,或者可以接受平台默认的字符集。

7.C

8.D 没说的

9.C

10.D

Serializable 接口 API 未定义任何方法体

11. C

三个方法执行顺序repaint() - update() - paint()

12.B

看 API:

readByte

public final byte readByte()

throws IOException参见 DataInput 的 readByte 方法的常规协定。

从所包含的输入流中读取此操作需要的字节

13.B,D 看看方法名字的含义就知道了了嘛

14..D 绘制图像,文字

15.D

这是它的构造方法之定义:

public FileOutputStream(File file)

throws FileNotFoundException创建一个向指定 File 对象表示的文件中写入数据的文件输出流

。创建一个新 FileDescriptor 对象来表示此文件连接

16.A

17 D

transient

参见:

18:C

19:A

由继承关系推导出来:

java.lang.Object

java.awt.Component

java.awt.Container

java.awt.Panel

java.applet.Applet

20.A

“发现构造函数要先于init方法执行:”

java程序设计与实践课程,大一菜鸟,有一道题求助!!!

for循环内  有问题

int k = score[0];

for(int j=0;jn;j++){

    if(k  score[j + 1]){

        k = score[j + 1];

    }

}

System.out.println("最大值是"+max);

JAVA程序设计题(很简单的)

你的题有很多错误,我给你改了一下。

1.设变量i和j的定义如下,试分别计算下列表达式的值:

int i=1; double d=1.0;

1题 35/4 [8]

2题 46%9+4*4-2 [15]

3题 45+43%5*(23*3%2)[48]

4题 45+45*50%i-- [45]

5题 45+45*50%(i--) [45]

6题 1.5*3+(++d) [6.5]

7题 1.5*3+d++ [5.5]

8题 i+=3/i+3 [7]

程序阅读题

1给定如下代码,写出程序运行结果

class Example{

public static void main(String arges[]){

int i=0;

do{

System.out.println("doing it for i is:"+i);

}while(--i0);

System.out.println("finish");

}

}

结果如下:

doing it for i is:0

finish

2 阅读程序段写出执行结果

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

if(k4)break;

System.out.println("k="+k);

}

结果:

k=1

k=2

k=3

k=4

3试写出下列程序段循环的运行结果

int i=1;

while(i10)

if(i++%2==0)

System.out.println(i);

结果:

3

5

7

9

操作题

求1!+2!+...+10!

public static void main(String arges[]){

long sum = 0;

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

long s = 1;

for(int j = 1; j = i; j++) {

s *= j;

}

sum += s;

}

System.out.println("sum = " + sum);

}

求100之内的所有“完数”。完数是指等于它的因子和的数。例如:6=1+2+3,6=1*2*3,则6是一个完数

public class wanshu{

public static void main(String[] args) {

for(int i = 1; i = 100; i++) {

if(fun(i)) {

System.out.println(i);

}

}

}

public static boolean fun(int num) {

int sum = 0;

for(int i = 1; i num; i++) {

if(num % i == 0) {

sum += i;

}

}

return num == sum;

}

}

关于大一java程序设计习题和java程序设计考题的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

The End

发布于:2022-12-03,除非注明,否则均为首码项目网原创文章,转载请注明出处。