import java.util.*;
成都創(chuàng)新互聯(lián)專注于網(wǎng)站建設(shè)|網(wǎng)站建設(shè)維護(hù)|優(yōu)化|托管以及網(wǎng)絡(luò)推廣,積累了大量的網(wǎng)站設(shè)計(jì)與制作經(jīng)驗(yàn),為許多企業(yè)提供了網(wǎng)站定制設(shè)計(jì)服務(wù),案例作品覆蓋茶樓設(shè)計(jì)等行業(yè)。能根據(jù)企業(yè)所處的行業(yè)與銷售的產(chǎn)品,結(jié)合品牌形象的塑造,量身策劃品質(zhì)網(wǎng)站。
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;
}
}
}
像這樣就好了.你需要保證每一種可能都有一個(gè)返回值
//瞧代碼
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) //將字符串?dāng)?shù)據(jù)轉(zhuǎn)化為數(shù)組
{
String vector[] = new String[20];
String regex = " ";
Pattern p = Pattern.compile(regex); //按照 空格進(jìn)行分割
String[] r = p.split("input"); //分割input并產(chǎn)生數(shù)組
for (int i = 0; i r.length; i++) {
vector[i] = r[i].trim();
// if (!((r[i].trim()).equals("")))
// ; //去掉該字符串首尾的空格、制表符等空白字符匹配項(xiàng)
// {
// }
}
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("排序結(jié)果:", 10, 30);
label1 = new Label("載入文件,輸入地址");
label2 = new Label("手動(dòng)輸入數(shù)據(jù)");
label3 = new Label("排序結(jié)果");
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(); //提取輸入的數(shù)據(jù)
huancun2 = text2.getText();
if (e.getSource() == button) //按鈕出發(fā)時(shí),開始運(yùn)算
{
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;
} //得到需要排序的字符串形式的數(shù)組
else {
return null;
}
double[] go = shengchengshuzu(shuju); //字符串轉(zhuǎn)為數(shù)組
double[] result = bubble(go); //排序
String over = result.toString(); //排序結(jié)果轉(zhuǎn)為字符串
return over;
}}
改 了一下你的代碼,供參考:
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(){//循環(huán)內(nèi)和循環(huán)外都應(yīng)該返回,因?yàn)橛锌赡苎h(huán)不執(zhí)行
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;
}
}
MouseListener是一個(gè)接口,要實(shí)現(xiàn)里面的抽象方法就行了
正確代碼如下:
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);//添加監(jiān)聽者 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 自動(dòng)生成的方法存根
}
@Override
public void mousePressed(MouseEvent e) {
// TODO 自動(dòng)生成的方法存根
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO 自動(dòng)生成的方法存根
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO 自動(dòng)生成的方法存根
}
@Override
public void mouseExited(MouseEvent e) {
// TODO 自動(dòng)生成的方法存根
}
}
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("學(xué)生的名字" + 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());
}
}
注意兩點(diǎn)問題:
1: 變量名重復(fù) s變量被覆蓋
2:沒有調(diào)用Vector.add方法添加元素
錯(cuò)誤點(diǎn)我都已經(jīng)給你注釋出來了
并且貼出了正確的代碼
結(jié)貼吧。。
當(dāng)前文章:java寫單詞糾錯(cuò)代碼 java重寫方法報(bào)錯(cuò)
網(wǎng)頁URL:http://muchs.cn/article0/docsooo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄、軟件開發(fā)、動(dòng)態(tài)網(wǎng)站、營銷型網(wǎng)站建設(shè)、全網(wǎng)營銷推廣、網(wǎng)站設(shè)計(jì)公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容