java经典上机编程题(java上机题 请问这道题应该怎么写)

:暂无数据 2026-09-07 01:10:06 :3

java经典上机编程题(java上机题 请问这道题应该怎么写)

大家好,java经典上机编程题相信很多的网友都不是很明白,包括java上机题 请问这道题应该怎么写也是一样,不过没有关系,接下来就来为大家分享关于java经典上机编程题和java上机题 请问这道题应该怎么写的一些知识点,大家可以关注收藏,免得下次来找不到哦,下面我们开始吧!

本文目录

java上机题 请问这道题应该怎么写

这道JAVA编程题代码要怎么写求代码
编写一个飞机(Plane)类,包含以下属性:
域:初始位置,初始速度,加速度
方法:到达某个位置需要的时间public double arrive(double 目标位置){return 时间}
两个飞机追及时间public double meet(Plane 另一个飞机){return 追及时间}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package test;
public class Plane {
double startPos;
double startSpeed;
double advance;
public Plane(double startPos,double startSpeed,double advance)
{
this.startPos=startPos;
this.startSpeed=startSpeed;
this.advance=advance;
}
public double arrive(double destPos)
{
double time;
time = (-startSpeed+(Math.sqrt(startSpeed*startSpeed+2*advance*(destPos-startPos))))/(advance);
return time;
}
public double chase(Plane plane)
{
double distance = plane.startPos-this.startPos;
double dspeed=-(plane.startSpeed-this.startSpeed);
double dadv = -(plane.advance-this.advance);
double time=0.0;
time=(-dspeed+(Math.sqrt(dspeed*dspeed+2*dadv*(distance))))/dadv;
return time;
}
public static void main(String args) {
Plane p1 = new Plane(1.0,2.0,0.5);
System.out.println(p1.arrive(3.0));
System.out.println(p1.chase(new Plane(5.0,1.5,0.3)));
}
}
以上是代码测试

java上机实验题,要求用java编写,完成其中随便一个就行,急求,能加多少分我就给多少分!!!

package testTime;
import java.util.LinkedList;
public class BinaryTree {
//根节点
private Node《Integer》 root;

//二叉树中节点数量
private int size;

//无参构造器
public BinaryTree() {
root = new Node《Integer》();
}

//数组构造器
public BinaryTree(int values) {
System.out.print("新建binaryTree:");
for (int i : values) {
System.out.print(i);
}
System.out.println();
boolean isLeft = true;
int len = values.length;
if (len == 0)
return ;
LinkedList《Node《Integer》》 queue = new LinkedList《Node《Integer》》();
root = new Node《Integer》(values);
queue.addLast(root);
Node parent = null;
Node current = null;
for (int i=1; i《len; i++) {
current = new Node《Integer》(values);
queue.addLast(current);
if (isLeft)
parent = queue.getFirst();
else
parent = queue.removeFirst();
if (isLeft) {
parent.setLeftChild(current);
isLeft = false;
}else {
parent.setRightChild(current);
isLeft = true;
}
}
}
//递归中序遍历
public void inorder() {
System.out.print("binaryTree递归中序遍历:");
inorderTraverseRecursion(root);
System.out.println();
}

//层次遍历
public void layerorder() {
System.out.print("binaryTree层次遍历:");
LinkedList《Node《Integer》》 queue = new LinkedList《Node《Integer》》();
queue.addLast(root);
Node《Integer》 current = null;
while(!queue.isEmpty()) {
current = queue.removeFirst();
if (current.getLeftChild() != null)
queue.addLast(current.getLeftChild());
if (current.getRightChild() != null)
queue.addLast(current.getRightChild());
System.out.print(current.getValue());
}
System.out.println();
}
//获得二叉树深度
public int getDepth() {
return getDepthRecursion(root);
}

private int getDepthRecursion(Node《Integer》 node){
if (node == null)
return 0;
int llen = getDepthRecursion(node.getLeftChild());
int rlen = getDepthRecursion(node.getRightChild());
int maxlen = Math.max(llen, rlen);
return maxlen + 1;
}
//递归先序遍历
public void preorder() {
System.out.print("binaryTree递归先序遍历:");
preorderTraverseRecursion(root);
System.out.println();
}
private void inorderTraverseRecursion(Node《Integer》 node) {
// TODO Auto-generated method stub
if (node.getLeftChild() != null)
inorderTraverseRecursion(node.getLeftChild());
System.out.print(node.getValue());
if (node.getRightChild() != null)
inorderTraverseRecursion(node.getRightChild());
}
private void preorderTraverseRecursion(Node《Integer》 node){
System.out.print(node.getValue());
if (node.getLeftChild() != null)
preorderTraverseRecursion (node.getLeftChild());
if (node.getRightChild() != null)
preorderTraverseRecursion (node.getRightChild());
}

//非递归先序遍历
public void preorderNoRecursion() {
System.out.print("binaryTree非递归先序遍历:");
LinkedList《Node《Integer》》 stack = new LinkedList《Node《Integer》》();
stack.push(root);
Node《Integer》 current = null;
while (!stack.isEmpty()) {
current = stack.pop();
System.out.print(current.getValue());
if (current.getRightChild() != null)
stack.push(current.getRightChild());
if (current.getLeftChild() != null)
stack.push(current.getLeftChild());
}
System.out.println();
}

/**
* 非递归中序遍历
* 栈内保存将要访问的元素
*/
public void inorderNoRecursion() {
System.out.print("binaryTree非递归中序遍历:");
LinkedList《Node《Integer》》 stack = new LinkedList《Node《Integer》》();
Node《Integer》 current = root;
while (current != null || !stack.isEmpty()) {
while(current != null) {
stack.push(current);
current = current.getLeftChild();
}
if (!stack.isEmpty()) {
current = stack.pop();
System.out.print(current.getValue());
current = current.getRightChild();
}
}
System.out.println();
}

/**
* 非递归后序遍历
* 当上一个访问的结点是右孩子或者当前结点没有右孩子则访问当前结点
*/
public void postorderNoRecursion() {
System.out.print("binaryTree非递归后序遍历:");
Node《Integer》 rNode = null;
Node《Integer》 current = root;
LinkedList《Node《Integer》》 stack = new LinkedList《Node《Integer》》();
while(current != null || !stack.isEmpty()) {
while(current != null) {
stack.push(current);
current = current.getLeftChild();
}
current = stack.pop();
while (current != null && (current.getRightChild() == null ||current.getRightChild() == rNode)) {
System.out.print(current.getValue());
rNode = current;
if (stack.isEmpty()){
System.out.println();
return;
}
current = stack.pop();
}
stack.push(current);
current = current.getRightChild();
}

}

public static void main(String args) {
BinaryTree bt = new BinaryTree(new int{1,2,3,4,5,6,7,8});
bt.inorder();
bt.preorder();
bt.layerorder();
bt.preorderNoRecursion();
bt.inorderNoRecursion();
bt.postorderNoRecursion();
System.out.println("深度为:" + bt.getDepth());
}
}
class Node《V》{
private V value;
private Node《V》 leftChild;
private Node《V》 rightChild;

public Node(){
};

public Node(V value) {
this.value = value;
leftChild = null;
rightChild = null;
}

public void setLeftChild(Node《V》 lNode) {
this.leftChild = lNode;
}

public void setRightChild(Node《V》 rNode) {
this.rightChild = rNode;
}
public V getValue() {
return value;
}
public void setValue(V value) {
this.value = value;
}
public Node《V》 getLeftChild() {
return leftChild;
}
public Node《V》 getRightChild() {
return rightChild;
}
}

简单的Java编程题

import javax.swing.*;
import java.awt.*;
public class TableDemo
{
private JFrame f;
private JTable table;
private String str;
private String column={"姓名","性别","籍贯","年龄"};

public TableDemo()
{
f=new JFrame();
Container con=f.getContentPane();
con.setLayout(new FlowLayout());
str=new String;
str="张先生";
str="男";
str="河北省邯郸市";
str="23";
table=new JTable(str,column);
con.add(new JScrollPane(table));
f.setSize(500,500);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String args)
{
new TableDemo();
}
}
希望这个对你有所帮助。
good luck to you!

求助大神!!JAVA上机题!!!

import java.util.Scanner;
public class Noname2
{
public static void main(String args) {
Scanner br = new Scanner(System.in);
String s = br.next();
char temp = s.toCharArray();
for(int i = temp.length - 1; i 》= 0; i--)
{
if(temp 《= 122)
{
temp - 32);
System.out.print(temp);
}
else
{
if(temp 《= 90)
{
temp + 32);
System.out.print(temp);
}
else
System.out.print(temp);
}
}

System.out.println();
}
}

简单java编程题,运行成功追加20

1)用equals()方法判断,Test t=new Test(2,4); Test t1=new Test(2,4);是否相等。不相等
public class Test {
private int a;
private int b;

public Test(int a, int b){
this.a = a;
this.b = b;
}

public static void main(String args) {
Test t=new Test(2,4);
Test t1=new Test(2,4);

boolean isEqual = t.equals(t1);
System.out.println(isEqual);
}
}
2)设计一种手段,让t.equals(t1)相等.,结果相等。
public class Test {
private int a;
private int b;

public Test(int a, int b){
this.a = a;
this.b = b;
}

public static void main(String args) {
Test t=new Test(2,4);
Test t1=new Test(2,4);

boolean isEqual = t.equals(t1);
System.out.println(isEqual);
}

public boolean equals(Object o) {
if(o instanceof Test){
Test t2 = (Test) o;
return t2.a == this.a && t2.b == this.b;
}

return false;
}
}
总结:如果子类不重写Object.equals()方法,那么两个对象比较的是内存地址;如果子类重写equals()方法,里面可以根据自己的需要来定义,从而避免比较内存地址。。

关于java经典上机编程题和java上机题 请问这道题应该怎么写的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

java经典上机编程题(java上机题 请问这道题应该怎么写)

本文编辑:admin

更多文章:


网站模板下载好以后(动态网站模板下载后怎么用)

网站模板下载好以后(动态网站模板下载后怎么用)

“网站模板下载好以后”相关信息最新大全有哪些,这是大家都非常关心的,接下来就一起看看网站模板下载好以后(动态网站模板下载后怎么用)!

2026年11月6日 22:50

选项卡的作用(excel中的“数字”选项卡的功能)

选项卡的作用(excel中的“数字”选项卡的功能)

本篇文章给大家谈谈选项卡的作用,以及excel中的“数字”选项卡的功能对应的知识点,文章可能有点长,但是希望大家可以阅读完,增长自己的知识,最重要的是希望对各位有所帮助,可以解决了您的问题,不要忘了收藏本站喔。

2026年11月6日 22:20

vb手机版下载(有谁可以告诉我vb在哪里下载)

vb手机版下载(有谁可以告诉我vb在哪里下载)

“vb手机版下载”相关信息最新大全有哪些,这是大家都非常关心的,接下来就一起看看vb手机版下载(有谁可以告诉我vb在哪里下载)!

2026年11月6日 21:50

指针变量和指针的关系(变量指针和指针变量有什么区别和联系)

指针变量和指针的关系(变量指针和指针变量有什么区别和联系)

大家好,如果您还对指针变量和指针的关系不太了解,没有关系,今天就由本站为大家分享指针变量和指针的关系的知识,包括变量指针和指针变量有什么区别和联系的问题都会给大家分析到,还望可以解决大家的问题,下面我们就开始吧!

2026年11月6日 21:30

dos命令清屏(Windows DOS内部命令详解04——del、ren、cls、ver、date、time)

dos命令清屏(Windows DOS内部命令详解04——del、ren、cls、ver、date、time)

“dos命令清屏”相关信息最新大全有哪些,这是大家都非常关心的,接下来就一起看看dos命令清屏(Windows DOS内部命令详解04——del、ren、cls、ver、date、time)!

2026年11月6日 15:40

constantly的用法及词组(英语时态对应的时间状语都有哪些)

constantly的用法及词组(英语时态对应的时间状语都有哪些)

本篇文章给大家谈谈constantly的用法及词组,以及英语时态对应的时间状语都有哪些对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

2026年11月6日 15:20

sql2016安装后如何打开(怎么打开sql server 2016 管理工具)

sql2016安装后如何打开(怎么打开sql server 2016 管理工具)

本篇文章给大家谈谈sql2016安装后如何打开,以及怎么打开sql server 2016 管理工具对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

2026年11月6日 15:10

编程基础指令(数控编程指令有哪些)

编程基础指令(数控编程指令有哪些)

大家好,今天小编来为大家解答以下的问题,关于编程基础指令,数控编程指令有哪些这个很多人还不知道,现在让我们一起来看看吧!

2026年11月6日 12:50

如何运行perl教程(怎样把自己的电脑设置成服务器)

如何运行perl教程(怎样把自己的电脑设置成服务器)

各位老铁们好,相信很多人对如何运行perl教程都不是特别的了解,因此呢,今天就来为大家分享下关于如何运行perl教程以及怎样把自己的电脑设置成服务器的问题知识,还望可以帮助大家,解决大家的一些困惑,下面一起来看看吧!

2026年11月6日 12:20

arcgis怎么设置文本框样式?用JS怎么实现一个把一个文本框中的选中内容加粗,效果基本上和编辑器的加粗效果相同急需

arcgis怎么设置文本框样式?用JS怎么实现一个把一个文本框中的选中内容加粗,效果基本上和编辑器的加粗效果相同急需

今天给各位分享arcgis怎么设置文本框样式的知识,其中也会对arcgis怎么设置文本框样式进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

2026年11月6日 10:50

最近更新

sony娱乐官网(索尼官方网站是什么)
2026-11-06 23:10:19 浏览:0
热门文章

新站如何通过网站维护提升SEO排名
2026-10-13 20:56:21 浏览:6
标签列表