java写单词纠错代码 java重写方法报错
java 代码纠错
import java.util.*;
成都创新互联专注于网站建设|网站建设维护|优化|托管以及网络推广,积累了大量的网站设计与制作经验,为许多企业提供了网站定制设计服务,案例作品覆盖茶楼设计等行业。能根据企业所处的行业与销售的产品,结合品牌形象的塑造,量身策划品质网站。
public class Final{
public static void main (String []args){
double AssignmentsScore=Assignments();
System.out.println(AssignmentsScore);
}
public static double Assignments(){
Scanner stdin = new Scanner(System.in);
System.out.println("Please input your Assignment1 score (out of a maximum of 10 marks each)");
double Assignment1=stdin.nextDouble();
if (Assignment1=1 Assignment1=10){
System.out.println("Please input your Assignment2 score (out of a maximum of 10 marks each)");
double Assignment2=stdin.nextDouble();
double AssignmentsScore=Assignment1+Assignment2;
return AssignmentsScore;
}else{
System.out.println("Please input the score between 1-10");
return 0;
}
}
}
像这样就好了.你需要保证每一种可能都有一个返回值
java代码纠错
//瞧代码
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.regex.Pattern;
public class paixuqi implements ActionListener
{
public double[] shengchengshuzu(String input) //将字符串数据转化为数组
{
String vector[] = new String[20];
String regex = " ";
Pattern p = Pattern.compile(regex); //按照 空格进行分割
String[] r = p.split("input"); //分割input并产生数组
for (int i = 0; i r.length; i++) {
vector[i] = r[i].trim();
// if (!((r[i].trim()).equals("")))
// ; //去掉该字符串首尾的空格、制表符等空白字符匹配项
// {
// }
}
double[] jieguo = new double[20];
for (int i = 0; i = 19; i++) {
jieguo[i] = Double.valueOf(vector[i]).doubleValue();
}
return jieguo;
}
public double[] bubble(double a[]) //冒泡排序
{
double temp;
int size = a.length;
for (int i = size - 1; i = 1; i--) {
for (int j = 0; j i; j++) {
if (a[j] a[j + 1]) {
temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}
return a;
}
String zhuanhuashuru(String a) throws IOException {
RandomAccessFile f = new RandomAccessFile(a, "r");
String record = f.readLine();
return record;
}
TextArea text1, text2, text3;
private Button button;
public static void main(String[] args) {
paixuqi px=new paixuqi();
px.initGUI();
}
public void initGUI() {
Label label1, label2, label3;
button = new Button("输入完毕");
Frame f = new Frame("paixuqi");
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
f.setLayout(new FlowLayout());
text1 = new TextArea("", 10, 30);
text2 = new TextArea("", 10, 30);
text3 = new TextArea("排序结果:", 10, 30);
label1 = new Label("载入文件,输入地址");
label2 = new Label("手动输入数据");
label3 = new Label("排序结果");
f.add(text1);
f.add(label1);
f.add(text2);
f.add(label2);
f.add(text3);
f.add(label3);
f.add(button);
f.setSize(780, 400);
// f.pack();
f.setVisible(true); //以上为操作界面描述
// text1.addActionListener(this);
// text2.addActionListener(this);
// text3.addActionListener(this);
button.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
String huancun1, huancun2;
huancun1 = text1.getText(); //提取输入的数据
huancun2 = text2.getText();
if (e.getSource() == button) //按钮出发时,开始运算
{
try {
text3.setText(paixu(huancun1, huancun2));
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
public String paixu(String s, String k) throws IOException {
String shuju;
if (s != null) {
shuju = zhuanhuashuru(s);
} else if (k != null) {
shuju = k;
} //得到需要排序的字符串形式的数组
else {
return null;
}
double[] go = shengchengshuzu(shuju); //字符串转为数组
double[] result = bubble(go); //排序
String over = result.toString(); //排序结果转为字符串
return over;
}}
java纠错
改 了一下你的代码,供参考:
package myExercise;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;
public class TestAnyType extends Comparable implements ComparableObject,ListAnyType{
private int theSize;
private AnyType [] theItems;
private AnyType [] theItems2;
public int size(){
return theSize;
}
public void ensureCapacity(int newCapacity){
if(newCapacity theSize)
return;
AnyType []old = theItems;
theItems = (AnyType []) new Object[ newCapacity ];
for( int i=0; isize(); i++)
theItems[i]=old[i];
}
public void add(int idx, AnyType x){
if(theItems.length == size())
ensureCapacity(size()*2+1);
for(int i=theSize; iidx; i--)
theItems[i]=theItems[i-1];
theItems[idx]=x;
theSize++;
}
public boolean judge(){
for(int i=0; i+1size(); i++){
if(theItems[i].compareTo(theItems[i+1])0){
return false;
}
else if(size()=1){
return false;
}
}return true;
}
public AnyType everyOther(){//循环内和循环外都应该返回,因为有可能循环不执行
for(int i=0;(2*i)size();i++){
theItems2[i]=theItems[2*i];
return theItems2[i];
}
return theItems2[0];
}
public boolean equalList(){
for(int i=0;isize();i++){
if(theItems2[i]!=theItems[i]){
return false;
}
}
return true;
}
public int compareTo(Object o) {
// TODO Auto-generated method stub
return 0;
}
public boolean add(AnyType e) {
// TODO Auto-generated method stub
return false;
}
public boolean addAll(Collection? extends AnyType c) {
// TODO Auto-generated method stub
return false;
}
public boolean addAll(int index, Collection? extends AnyType c) {
// TODO Auto-generated method stub
return false;
}
public void clear() {
// TODO Auto-generated method stub
}
public boolean contains(Object o) {
// TODO Auto-generated method stub
return false;
}
public boolean containsAll(Collection? c) {
// TODO Auto-generated method stub
return false;
}
public AnyType get(int index) {
// TODO Auto-generated method stub
return null;
}
public int indexOf(Object o) {
// TODO Auto-generated method stub
return 0;
}
public boolean isEmpty() {
// TODO Auto-generated method stub
return false;
}
public IteratorAnyType iterator() {
// TODO Auto-generated method stub
return null;
}
public int lastIndexOf(Object o) {
// TODO Auto-generated method stub
return 0;
}
public ListIteratorAnyType listIterator() {
// TODO Auto-generated method stub
return null;
}
public ListIteratorAnyType listIterator(int index) {
// TODO Auto-generated method stub
return null;
}
public boolean remove(Object o) {
// TODO Auto-generated method stub
return false;
}
public AnyType remove(int index) {
// TODO Auto-generated method stub
return null;
}
public boolean removeAll(Collection? c) {
// TODO Auto-generated method stub
return false;
}
public boolean retainAll(Collection? c) {
// TODO Auto-generated method stub
return false;
}
public AnyType set(int index, AnyType element) {
// TODO Auto-generated method stub
return null;
}
public ListAnyType subList(int fromIndex, int toIndex) {
// TODO Auto-generated method stub
return null;
}
public Object[] toArray() {
// TODO Auto-generated method stub
return null;
}
public T T[] toArray(T[] a) {
// TODO Auto-generated method stub
return null;
}
}
JAVA纠错
MouseListener是一个接口,要实现里面的抽象方法就行了
正确代码如下:
package test;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.*;
class Frame{
public static void main(String[] args)
{ MyJFrame mif=new MyJFrame("test");}
}
class MyJFrame extends JFrame implements MouseListener
{ JButton a=null; JButton b=null;
JButton c=null;
JPanel p1=new JPanel();
JPanel p2=new JPanel();
Container cp=null;
MyJFrame(){ this("no title"); }
MyJFrame(String title)
{
super(title);
a=new JButton("red");
b=new JButton("blue");
c=new JButton("yellow");
cp=getContentPane();
cp.add(p1,BorderLayout.CENTER);
p1.setBackground(Color.GREEN);
p2.add(a,BorderLayout.SOUTH);
p2.add(b,BorderLayout.SOUTH);
p2.add(c,BorderLayout.SOUTH);
cp.add(p2,BorderLayout.SOUTH);
p1.addMouseListener(this);//添加监听者 setSize(500,400); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationRelativeTo(null); setVisible(true); public void mousePressed(MouseEvent e){} public void mouseReleased(MouseEvent e){} public void mouseClicked(MouseEvent e){ if(a) p1.setBackground(Color.RED); if(b) p1.setBackground(Color.BLUE); if(c) p1.setBackground(Color.YELLO); } public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} }}
}
@Override
public void mouseClicked(MouseEvent e) {
// TODO 自动生成的方法存根
}
@Override
public void mousePressed(MouseEvent e) {
// TODO 自动生成的方法存根
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO 自动生成的方法存根
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO 自动生成的方法存根
}
@Override
public void mouseExited(MouseEvent e) {
// TODO 自动生成的方法存根
}
}
java编程纠错
import java.util.Vector;
public class Test2 {
class student {
String name;
int mark;
student(String n, int m) {
name = n;
mark = m;
}
public String getname() {
return name;
}
public int getJavaMark() {
return mark;
}
};
static Vectorstudent students = new Vectorstudent();//
static int t = getNum();
public static int getNum() {
return students.size();
}
public static int getAverage() {
int sum = 0;
int num = getNum();
for (int i = 0; i num; i++) {
sum = sum + students.get(i).getJavaMark();
}
return sum / num;
}
public static int gethighest() {
int num = getNum();
int temp = 0;
for (int j = 0; j num; j++) {
if (students.get(j).getJavaMark() temp)
temp = students.get(j).getJavaMark();
}
return temp;
}
public static int getlowest() {
int num = getNum();
int temp = 100;
for (int k = 0; k num; k++) {
if (students.get(k).getJavaMark() temp)
temp = students.get(k).getJavaMark();
}
return temp;
}
void display() {
for (int l = 0; l t; l++) {
System.out.println("学生的名字" + students.get(l).getname() + "java的成绩"
+ students.get(l).getJavaMark());
}
}
public static void main(String[] args) {
Test2 s = new Test2();
student s1 = s.new student("jimmy", 88);
student s2 = s.new student("Lucy", 90);
student s3 = s.new student("tiger", 100);
students.add(s1);//
students.add(s2);//
students.add(s3);//
s.display();
System.out.println(s.gethighest());
System.out.println(s.getlowest());
System.out.println(s.getAverage());
}
}
注意两点问题:
1: 变量名重复 s变量被覆盖
2:没有调用Vector.add方法添加元素
错误点我都已经给你注释出来了
并且贴出了正确的代码
结贴吧。。
网站栏目:java写单词纠错代码 java重写方法报错
本文网址:http://ybzwz.com/article/docsooo.html