「java上机实验常考点」java程序设计上机实验答案
本篇文章给大家谈谈java上机实验常考点,以及java程序设计上机实验答案对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
计算机2级JAVA都考些什么?
国计算机等级考试2级JAVA语言 考试大纲2008年最新版
基本要求:
1. 掌握Java语言的特点,实现机制和体系结构。
2. 掌握Java语言中面向对象的特性。
3. 掌握Java语言提供的数据类型和结构。
4. 掌握Java语言编程的基本技术。
5. 会编写Java用户界面程序。
6. 会编写Java简单应用程序。
7. 会编写Java小应用程序(Applet)。
8. 了解Java的应用。
考试内容:
一、 Java语言的特点和实现机制
二、 Java体系结构
1. JDK目录结构。
2. Java的API结构。
3. 开发环境设置。
4. Java程序结构。
三、 Java语言中面向对象的特性。
1. 面向对象编程的基本概念和特征。
2. 类的基本组成和使用。
3. 对象的生成、使用和删除。
4. 接口与包。
5. Java类库中常用类和接口。
四、 Java简单数据类型及运算
1. 变量和常量。
2. 基本数据类型及转换。
3. Java类库中对简单数据类型的类包装。
4. 运算符和表达式运算。
5. 数组和字符串。
五、 Java语言的基本语句
1. 表达式语句。
2. 条件语句。
3. 循环语句。
4. 注释语句。
5. 异常处理。
六、 Java编程技术基础
1. 线程的概念和使用。
2. 同步与共享。
3. 串行化概念和目的。
4. 串行化方法。
5. 串行化的举例。
6. 基于文本的应用。
7. 文件和文件I/O。
8. 汇集(collections)接口。
七、 编写用户界面程序
1. 图形用户界面。
2. AWT库简介。
3. Swing简介。
4. AWT与Swing比较。
八、 编写小应用程序(Applet)
1. 小应用程序概念。
2. 安全机制。
3. Applet执行过程。
4. Applet的图形绘制。
5. Applet的窗口。
6. Applet的工作环境。
7. Java Application 和Applet。
九、 Java的应用
十、 J2DK的下载和操作。
考试方式:
笔试:90分钟,满分100分,其中含公共基础知识部分的30分。
上机操作:90分钟,满分100分。
上机题目类型要求:
(1) 基本操作。
(2) 简单应用。
(3) 综合应用。
java上机面试题,求帮助
public class EncodeAndDecode {
/**
* 译码
*
* @param str
* 要译码的字符串
* @return 译码后的字符串
*/
public String encode(String str) throws StringLenException{
StringBuilder sb = new StringBuilder();
if(null == str) {
throw new StringLenException("字符串末初始化!");
}
int n = str.length();
if(n =0) {
throw new StringLenException("字符串不能为空!");
}
char c = 0;
int k = 0;
for (int i = 0; i n; i++) {
// 获得当前字符
c = str.charAt(i);
if (c = '1' c = '9' i != n-1) { // c是1-9的数字, 且in-1 复制(k+1)次后面的一个字符
k = c -'0' + 1;
for(int j=0; jk; j++) {
sb.append(str.charAt(i+1));
}
} else if (c == '_') { // c除1-9,且为”_” 转换为”\Ul”
sb.append("\\UL");
}else{ //其余 复制该字符
sb.append(c);
}
sb.append("_");
}
return sb.deleteCharAt(sb.length()-1).toString();
}
/**
* 解码
*
* @param str
* 要解码的字符串
* @return 解码后的字符串
*/
public String decode(String str) {
StringBuilder sb = new StringBuilder();
if(null == str) {
throw new StringLenException("字符串末初始化!");
}
if(sb.length() =0) {
throw new StringLenException("字符串不能为空!");
}
String strs[] = str.split("_");
char c = 0;
int k = 0;
int n = strs.length;
if(n == 1) {
sb.append(str);
} else {
for(int i=0; in; i++) {
k = strs[i].length();
c = strs[i].charAt(0);
if(1 ==k) { //k==1, 将该字符原样复原
sb.append(c);
} else { //k1,
if(strs[i].equals("\\UL")) {//strs[i] == ”\Ul”, 转换为”_”
sb.append("_");
} else { // strs[i] != ”\Ul”, 转换为k(k = strs[i].length()-1)
sb.append(k-1);
}
}
}
}
return sb.toString();
}
/**
* @param args
*/
public static void main(String[] args) {
String s = "24ab_2t2";
// String s = "04ab_2t2";
// String s = "1a0b_2t2";
// String s = "aaab_2t2";
// String s = "24ab_2335t2";
// String s = "240ab_";
/*EncodeAndDecode encode = new EncodeAndDecode();
String s1 = encode.encode(s);
System.out.println("encode:" + s1);
String s2 = encode.decode(s1);
System.out.println("decode:" + s2);
*/
}
}
public class StringLenException extends RuntimeException {
public StringLenException() {
super();
}
public StringLenException(String message) {
super(message);
}
}
java上机实验题,要求用java编写,完成其中随便一个就行,急求,能加多少分我就给多少分!!!
package testTime;
import java.util.LinkedList;
public class BinaryTree {
//根节点
private NodeInteger root;
//二叉树中节点数量
private int size;
//无参构造器
public BinaryTree() {
root = new NodeInteger();
}
//数组构造器
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 ;
LinkedListNodeInteger queue = new LinkedListNodeInteger();
root = new NodeInteger(values[0]);
queue.addLast(root);
Node parent = null;
Node current = null;
for (int i=1; ilen; i++) {
current = new NodeInteger(values[i]);
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层次遍历:");
LinkedListNodeInteger queue = new LinkedListNodeInteger();
queue.addLast(root);
NodeInteger 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(NodeInteger 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(NodeInteger 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(NodeInteger 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非递归先序遍历:");
LinkedListNodeInteger stack = new LinkedListNodeInteger();
stack.push(root);
NodeInteger 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非递归中序遍历:");
LinkedListNodeInteger stack = new LinkedListNodeInteger();
NodeInteger 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非递归后序遍历:");
NodeInteger rNode = null;
NodeInteger current = root;
LinkedListNodeInteger stack = new LinkedListNodeInteger();
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 NodeV{
private V value;
private NodeV leftChild;
private NodeV rightChild;
public Node(){
};
public Node(V value) {
this.value = value;
leftChild = null;
rightChild = null;
}
public void setLeftChild(NodeV lNode) {
this.leftChild = lNode;
}
public void setRightChild(NodeV rNode) {
this.rightChild = rNode;
}
public V getValue() {
return value;
}
public void setValue(V value) {
this.value = value;
}
public NodeV getLeftChild() {
return leftChild;
}
public NodeV getRightChild() {
return rightChild;
}
}
Java 上机题目
public class BookTest{ public static void main(String[] args){ Book book = new Book("Cook book",150); book.detail(); }} class Book{ private String title; private int pageNum; public Book(String title,int pageNum){ this.title = title; this.judgePage(pageNum); } public String getTitle(){ return this.title; } public void setTitle(String title){ this.title=title; }public int getPageNum(){ return this.pageNum; }public void setPageNum(int pageNum){ this.pageNum=this.judgePage(pageNum);}private int judgePage(int pageNum){ if(pageNum200){ System.out.println("页数["+pageNum+"]不能小于200"); pageNum = 200;
} return pageNum;}public void detail(){ System.out.println("书名:"+this.title+"\n页数:"+this.pageNum);}}
java上机实验常考点的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java程序设计上机实验答案、java上机实验常考点的信息别忘了在本站进行查找喔。