
正文
java代码自动改写,自动生成java代码
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
java接口代码改写C#
C#中类的继承用通过冒号:实现,在Java中用extends
C#中实现接口通过冒号:实现,在Java中用implements
C#中密封类用sealed实现,在Java中用final
C#中常数用const实现,在Java中用final
C#中属性用set,get代码块实现,在Java中一般用类似于C#中的字段代表属性,或者用setter,getter构造器实现
相关问答
Q1: IntelliJ IDEA 13.1 JAVA 代码改错
把光标停到错误的地方 按下alt+enter,IDEA会给出解决办法。如导入包,修正代码错误等。
例如:
这是一个没有导入包的错误。把光标停到红色错误位置,按下ALT+Enter(回车)
IDEA给出提示,直接回车就可以自动导入jar引用。
Q2: Java 改写ArrayList的add方法让其变可以自动排序
public static class SortedArrayListE extends ComparableE extends ArrayListE
{
public boolean add(E e)
{
if(size()==0)
{
add(0,e);
return true;
}
else{
E value = e;
int x=0;
for(x=size(); x0; x--)
{
if (value.compareTo(get(x-1))0)
{
break;
}
}
add(x,value);
return true;
}
}
}
你的写法会出现死循环 然后就溢出了 你调试下就能看到
改成这样就行了
如果要从大到小把 if (value.compareTo(get(x-1))0)改成if (value.compareTo(get(x-1))0)
Q3: JAVA代码改写ArrayList
Student.java
public class Student {
private String name;
private int score;
public Student(String name, int score) {
this.name = name;
this.score = score;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
}
Array1dTester.java
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
public class Array1dTester {
public static void main(String args[]) {
int n = Integer.parseInt(JOptionPane.showInputDialog("Enter the number of students in the class."));
// Student[] student = new Student[n];
ListStudent students = new ArrayListStudent();
for (int i = 0; i n; i++) {
String studentName = JOptionPane.showInputDialog("Enter a name for student[" + i + "].");
int studentScore = Integer.parseInt(JOptionPane.showInputDialog("Enter a score for student[" + i + "]."));
Student newStudent = new Student(studentName, studentScore);
// student[i] = newStudent;
students.add(newStudent);
}
int sumOfScores = 0;
for (int i = 0; i students.size(); i++) {
sumOfScores += students.get(i).getScore();
}
float averageScore = (float) sumOfScores / (float) n;
int maxScore = students.get(0).getScore();
for (int i = 1; i n; i++) {
if (students.get(i).getScore() maxScore) {
maxScore = students.get(i).getScore();
}
}
int minScore = students.get(0).getScore();
for (int i = 1; i n; i++) {
if (students.get(i).getScore() minScore) {
minScore = students.get(i).getScore();
}
}
JOptionPane.showMessageDialog(null, "The class average is "+ averageScore + "\n" + "The class maximum score is "+ maxScore + "\n" + "The class minimum score is " + minScore+ "\n" + "Click OK run the ArrayList version.");
// ArrayList1dTester.arrayListMain();
}
}
运行结果:
补充说明:
该程序存在的bug:未对输入的值进行非空和非数字判断。。。比较简单。。你自行搞定吧。
Q4: java怎么让代码自动
你说的是Eclipse代码自动补全功能吧。可以实现输入任意字母均可出现代码补全提示框。
具体设置方式如下:
eclipse--windows--preferences--java--editor--content assist--右边设置如下图
红色箭头指向的地方设置为:
.abcdefghijklmnopqrstuvwxyz(26个字母全部写进去不区分大小写)
Q5: Java代码改写
接口,就是给别的应用。写public方法,写参数,写返回值,就可以






