真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

關(guān)于java300代碼的信息

求計算器Java代碼。。。

import java.awt.*;

在崇明等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務理念,為客戶提供網(wǎng)站建設(shè)、網(wǎng)站制作 網(wǎng)站設(shè)計制作按需定制制作,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站設(shè)計,成都全網(wǎng)營銷推廣,成都外貿(mào)網(wǎng)站建設(shè),崇明網(wǎng)站建設(shè)費用合理。

import javax.swing.*;

import java.awt.event.*;

import javax.swing.event.*;

class JPanelEa1 extends JFrame implements MenuListener,ActionListener

{

JPanel mainp,p1,p2,p3,p4;

JTextField jt1;

JMenuItem mnuCopy;

JMenuItem mnuPaste;

JButton bM;

boolean isDouble = false;// 是否為實數(shù)

int opFlag = -1;

static double t1 = 0, t2 = 0, t3 = 0, result = 0;

static int opflag1 = -1, opflag2 = -1, flag = 0, resflag = 1;

int preOp, currentOp = 0;// 標準位

double op1 = 0, op2 = 0;// 操作數(shù)

double n3;

StringBuffer buf = new StringBuffer(20);

StringBuffer copyBoard = new StringBuffer(20);// 剪貼板

StringBuffer memory = new StringBuffer(20);// M系列

StringBuffer str = new StringBuffer();

public JPanelEa1()

{

p1=new JPanel();

p1.setLayout(new GridLayout(2,1,10,10));

JMenuBar mnuNotepad=new JMenuBar();

JMenu mnuEdit=new JMenu("編輯(E)");

mnuEdit.setMnemonic(KeyEvent.VK_E);

JMenu mnuCheck=new JMenu("查看(V)");

mnuCheck.setMnemonic(KeyEvent.VK_V);

JMenu mnuHelp=new JMenu("幫助(H)");

mnuCopy=new JMenuItem("復制(C)");

mnuPaste=new JMenuItem("粘貼(P)");

JMenuItem mnuVisit=new JMenuItem("查看幫助(V)");

JMenuItem mnuAbout=new JMenuItem("關(guān)于計算器(A)");

JSeparator sep=new JSeparator();

jt1=new JTextField("0.");

jt1.setEnabled(false);

jt1.setHorizontalAlignment(JTextField.RIGHT);

mnuEdit.addMenuListener(this);

mnuCheck.addMenuListener(this);

mnuHelp.addMenuListener(this);

mnuCopy.addActionListener(this);

mnuPaste.addActionListener(this);

mnuVisit.addActionListener(this);

mnuAbout.addActionListener(this);

mnuNotepad.add(mnuEdit);

mnuNotepad.add(mnuCheck);

mnuNotepad.add(mnuHelp);

mnuEdit.add(mnuCopy);

mnuEdit.add(mnuPaste);

mnuEdit.add(sep);

mnuHelp.add(mnuVisit);

mnuHelp.add(sep);

mnuHelp.add(mnuAbout);

p1.add(mnuNotepad);

p1.add(jt1);

p2=new JPanel();

p2.setLayout(new FlowLayout(FlowLayout.CENTER));

bM = new JButton(" ");

bM.setEnabled(false);

p2.add(bM);

Button b25=new Button("Backspace");

b25.addActionListener(this);

Button b26=new Button("CE");

b26.addActionListener(this);

Button b27=new Button("C");

b27.addActionListener(this);

p2.add(b25);

p2.add(b26);

p2.add(b27);

p3=new JPanel();

p3.setLayout(new GridLayout(4,6));

Button button1=new Button("MC");

button1.addActionListener(this);

Button button2=new Button("7");

button2.addActionListener(this);

Button button3=new Button("8");

button3.addActionListener(this);

Button button4=new Button("9");

button4.addActionListener(this);

Button button5=new Button("/");

button5.addActionListener(this);

Button button6=new Button("sqrt");

button6.addActionListener(this);

Button button7=new Button("MR");

button7.addActionListener(this);

Button button8=new Button("4");

button8.addActionListener(this);

Button button9=new Button("5");

button9.addActionListener(this);

Button button10=new Button("6");

button10.addActionListener(this);

Button button11=new Button("*");

button11.addActionListener(this);

Button button12=new Button("%");

button12.addActionListener(this);

Button button13=new Button("MS");

button13.addActionListener(this);

Button button14=new Button("1");

button14.addActionListener(this);

Button button15=new Button("2");

button15.addActionListener(this);

Button button16=new Button("3");

button16.addActionListener(this);

Button button17=new Button("-");

button17.addActionListener(this);

Button button18=new Button("1/x");

button18.addActionListener(this);

Button button19=new Button("M+");

button19.addActionListener(this);

Button button20=new Button("0");

button20.addActionListener(this);

Button button21=new Button("+/-");

button21.addActionListener(this);

Button button22=new Button(".");

button22.addActionListener(this);

Button button23=new Button("+");

button23.addActionListener(this);

Button button24=new Button("=");

button24.addActionListener(this);

p3.add(button1);p3.add(button2);

p3.add(button3);p3.add(button4);

p3.add(button5);p3.add(button6);

p3.add(button7);p3.add(button8);

p3.add(button9);p3.add(button10);

p3.add(button11);p3.add(button12);

p3.add(button13);p3.add(button14);

p3.add(button15);p3.add(button16);

p3.add(button17);p3.add(button18);

p3.add(button19);p3.add(button20);

p3.add(button21);p3.add(button22);

p3.add(button23);p3.add(button24);

setSize(250,150);

mainp=new JPanel();

mainp.setLayout(new GridLayout(3,1));

mainp.add(p1);

mainp.add(p2);

mainp.add(p3);

setContentPane(mainp);

setTitle("計算器");

setSize(300,300);

setVisible(true);

setDefaultCloseOperation(EXIT_ON_CLOSE);

}

public void actionPerformed(ActionEvent e)

{

String s= e.getActionCommand();

if (s.equals("復制(C)")) {

String temp = jt1.getText().trim();

copyBoard.replace(0, copyBoard.length(), temp);

mnuPaste.setEnabled(true);

} else if (s.equals("粘貼(p)")) {

jt1.setText(copyBoard.toString());

} else if (s.equals("CE")) {

// 如果是CE則清除文本框

jt1.setText("0.");

} else if (s.equals("Backspace")) {

if (!jt1.getText().trim().equals("0.")) {

// 如果文本框中有內(nèi)容

if (str.length() != 1 str.length() != 0) {

jt1.setText(str.delete(str.length() - 1, str.length())

.toString());

} else {

jt1.setText("0.");

str.setLength(0);

}

}

op2 = Double.parseDouble(jt1.getText().trim());

} else if (s.equals("C")) {

// 如果是C刪除當前計算

jt1.setText("0.");

op1 = op2 = 0;

str.replace(0, str.length(), " ");

preOp = currentOp = 0;

} else if (s.equals("MC")) {

// 如果是MC則清除緩沖區(qū)

String temp = "";

memory.replace(0, memory.length(), temp);

bM.setText(" ");

} else if (s.equals("MR")) {

// 如果按鍵為MR則恢復緩沖區(qū)的數(shù)到文本框

jt1.setText(memory.toString());

} else if (s.equals("MS")) {

// 如果按鍵為MS則將文本框的數(shù)存入緩沖區(qū)

String s1 = jt1.getText().trim();

memory.replace(0, memory.length(), s1);

bM.setText("M");

} else if (s.equals("M+")) {

// 如果按鍵為MS則將文本框值與緩沖區(qū)的數(shù)相加但不顯示結(jié)果

String temp1 = jt1.getText().trim();

double dtemp = Double.parseDouble(temp1);

String temp2 = memory.toString();

dtemp += Double.parseDouble(temp2);

temp1 = String.valueOf(dtemp);

memory.replace(0, memory.length(), temp1);

} else if (s.equals("1/x")) {

// 如果按鍵為1/x則將文本框中的數(shù)據(jù)為它的倒數(shù)

String temp = jt1.getText().trim();

double dtemp = Double.parseDouble(temp);

jt1.setText("" + 1 / dtemp);

} else if (s.equals("sqrt")) {

// 如果按鍵為sqrt則將文本框中的內(nèi)容求平方根

String temp = jt1.getText().trim();

double dtemp = Double.parseDouble(temp);

jt1.setText("" + Math.sqrt(dtemp));

} else if (s.equals("+")) {

str.setLength(0);

if (currentOp == 0) {

preOp = currentOp = 1;

op2 = 0;

jt1.setText("" + op1);

} else {

currentOp = preOp;

preOp = 1;

switch (currentOp) {

case 1:

op1 += op2;

jt1.setText("" + op1);

break;

case 2:

op1 -= op2;

jt1.setText("" + op1);

break;

case 3:

op1 *= op2;

jt1.setText("" + op1);

break;

case 4:

op1 /= op2;

jt1.setText("" + op1);

break;

}

}

} else if (s.equals("-")) {

str.setLength(0);

if (currentOp == 0) {

preOp = currentOp = 2;// op1=op2;op2=0;

jt1.setText("" + op1);

} else {

currentOp = preOp;

preOp = 2;

switch (currentOp) {

case 1:

op1 = op1 + op2;

jt1.setText("" + op1);

break;

case 2:

op1 = op1 - op2;

jt1.setText("" + op1);

break;

case 3:

op1 = op1 * op2;

jt1.setText("" + op1);

break;

case 4:

op1 = op1 / op2;

jt1.setText("" + op1);

break;

}

}

} else if (s.equals("*"))// *

{

str.setLength(0);

if (currentOp == 0) {

preOp = currentOp = 3;// op1=op2;op2=1;

jt1.setText("" + op1);// op1=op2;

} else {

currentOp = preOp;

preOp = 3;

switch (currentOp) {

case 1:

op1 = op1 + op2;

jt1.setText("" + op1);

break;

case 2:

op1 = op1 - op2;

jt1.setText("" + op1);

break;

case 3:

op1 = op1 * op2;

jt1.setText("" + op1);

break;

case 4:

op1 = op1 / op2;

jt1.setText("" + op1);

break;

}

}

} else if (s.equals("/"))// /

{

str.setLength(0);

if (currentOp == 0) {

preOp = currentOp = 4;// op2=1;

jt1.setText("" + op1);// op1=op2;

} else {

currentOp = preOp;

preOp = 4;

switch (currentOp) {

case 1:

op1 = op1 + op2;

jt1.setText("" + op1);

break;

case 2:

op1 = op1 - op2;

jt1.setText("" + op1);

break;

case 3:

op1 = op1 * op2;

jt1.setText("" + op1);

break;

case 4:

op1 = op1 / op2;

jt1.setText("" + op1);

break;

}

}

} else if (s.equals("="))// =

{

if (currentOp == 0) {

str.setLength(0);

jt1.setText("" + op2);

} else {

str.setLength(0);

currentOp = preOp;

switch (currentOp) {

case 1:

op1 = op1 + op2;

jt1.setText("" + op1);

break;

case 2:

op1 = op1 - op2;

jt1.setText("" + op1);

break;

case 3:

op1 = op1 * op2;

jt1.setText("" + op1);

break;

case 4:

op1 = op1 / op2;

jt1.setText("" + op1);

break;

}

currentOp = 0;

op2 = 0;

}

} else if (s.equals(".")) {

isDouble = true;

if (jt1.getText().trim().indexOf('.') != -1)

;

else {

if (jt1.getText().trim().equals("0")) {

str.setLength(0);

jt1.setText((str.append("0" + s)).toString());

}

// else

// if(jt1.getText().trim().equals("")){}//如果初時顯示為空則不做任何操作

else {

jt1.setText((str.append(s)).toString());

}

}

} else if (s.equals("0"))// 如果選擇的是"0"這個數(shù)字鍵

{

if (jt1.getText().trim().equals("0.")) {

} else {

jt1.setText(str.append(s).toString());

op2 = Double.parseDouble(jt1.getText().trim());

}

} else {

jt1.setText(str.append(s).toString());

op2 = Double.parseDouble(jt1.getText().trim());

if (currentOp == 0)

op1 = op2;

}

}

public static void main(String args[])

{

JPanelEa1 g=new JPanelEa1();

}

@Override

public void menuSelected(MenuEvent e) {

// TODO Auto-generated method stub

}

@Override

public void menuDeselected(MenuEvent e) {

// TODO Auto-generated method stub

}

@Override

public void menuCanceled(MenuEvent e) {

// TODO Auto-generated method stub

}

}

輸出300以內(nèi)奇數(shù)之和java代碼

public?class?Test?{

public?static?void?main(String[]?args)?{

int?sum?=?0;

for?(int?i?=?0;?i??300;?i++)?{

if?(i?%?2?!=?0)?{

sum?+=?i;

}

}

System.out.println(sum);

}

}

用java語言打印300~0之間的隨機數(shù)且步長(每兩個相鄰隨機數(shù)之間的差)小于5

先求一個0到300 的隨機數(shù) 這個簡單吧 ,Java里的隨機數(shù)是取的0到1的數(shù),你放大300倍取整就是0到300的隨機數(shù),然后你把這個數(shù)大于5 且不超過300 的值拿到 再取小于5但是不小于0的值拿到,然后在這些數(shù)里隨機去一個數(shù),依次類推。

比如第一次取的是 10 那么 下次隨機數(shù)就是 5到15 之間,不包括5和15的話,加上10是9個數(shù)(6到14),那么取0到1的隨機數(shù)乘以9加上6 取整就是你第二個隨機數(shù) ,依次類推

求編寫一個超級簡單的Java的程序源代碼

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

class ConstructFrame extends JFrame

{

private static final long serialVersionUID = 1L;

String value1="",result,value2="";

int flag=0,fix=0,sum=1;

Boolean happy;

JTextField text=new JTextField(30);

int flagsum=0;

Container c=getContentPane();

JButton buttonx;

ConstructFrame()

{ super("計算器");

c.setLayout(null);

c.setBackground(Color.blue);

this.setSize(400, 400);

c.add(text);

text.setHorizontalAlignment(JTextField.RIGHT);

final JButton buttonx=new JButton("BackSpace");

c.add(buttonx);

buttonx.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

int count=0;

String temp;

if(flag==0)

{

count=value1.length();

if(count!=1)

temp=value1.substring(0, count-1);

else

temp="0";

value1=temp;

}

else

{

count=value2.length();

if(count!=1)

temp=value2.substring(0, count-1);

else

temp="0";

value2=temp;

}

text.setText(temp);

}

});

final JButton buttony=new JButton("CE");

c.add(buttony);

buttony.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

value1="";

value2="";

flag=0;

text.setText("0");

}

});

final JButton button1=new JButton("1");

c.add(button1);

button1.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

String temp;

if(flag==0)

{

value1=value1+1;

temp=value1;

}

else

{

value2=value2+1;

temp=value2;

}

text.setText(temp);

}

});

final JButton button2=new JButton(" 2 ");

c.add(button2);

button2.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

String temp;

if(flag==0)

{

value1=value1+2;

temp=value1;

}

else

{

value2=value2+2;

temp=value2;

}

text.setText(temp);

}

});

final JButton button3=new JButton("3");

c.add(button3);

button3.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

String temp;

if(flag==0)

{

value1=value1+3;

temp=value1;

}

else

{

value2=value2+3;

temp=value2;

}

text.setText(temp);

}

});

final JButton button4=new JButton("4");

c.add(button4);

button4.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

String temp;

if(flag==0)

{

value1=value1+4;

temp=value1;

}

else

{

value2=value2+4;

temp=value2;

}

text.setText(temp);

}

});

final JButton button5=new JButton("5");

c.add(button5);

button5.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

String temp;

if(flag==0)

{

value1=value1+5;

temp=value1;

}

else

{

value2=value2+5;

temp=value2;

}

text.setText(temp);

}

});

final JButton button6=new JButton("6");

c.add(button6);

button6.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

String temp;

if(flag==0)

{

value1=value1+6;

temp=value1;

}

else

{

value2=value2+6;

temp=value2;

}

text.setText(temp);

}

});

final JButton button7=new JButton("7");

c.add(button7);

button7.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

String temp;

if(flag==0)

{

value1=value1+7;

temp=value1;

}

else

{

value2=value2+7;

temp=value2;

}

text.setText(temp);

}

});

final JButton button8=new JButton("8");

c.add(button8);

button8.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

String temp;

if(flag==0)

{

value1=value1+8;

temp=value1;

}

else

{

value2=value2+8;

temp=value2;

}

text.setText(temp);

}

});

final JButton button9=new JButton("9");

c.add(button9);

button9.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

String temp;

if(flag==0)

{

value1=value1+9;

temp=value1;

}

else

{

value2=value2+9;

temp=value2;

}

text.setText(temp);

}

});

final JButton button0=new JButton("0");

c.add(button0);

button0.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

String temp;

if(flag==0)

{

value1=value1+0;

temp=value1;

}

else

{

value2=value2+0;

temp=value2;

}

text.setText(temp);

}

});

final JButton buttonadd=new JButton(" + ");

c.add(buttonadd);

buttonadd.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

flag=1;

fix=1;

flagsum=0;

}

});

final JButton buttonsubtract=new JButton(" - ");

c.add(buttonsubtract);

buttonsubtract.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

flag=1;

fix=2;

flagsum=0;

}

});

final JButton buttoncheng=new JButton(" * ");

c.add(buttoncheng);

buttoncheng.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

flag=1;

fix=3;

flagsum=0;

}

});

final JButton buttonchu=new JButton(" / ");

c.add(buttonchu);

buttonchu.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

flag=1;

flagsum=0;

fix=4;

}

});

final JButton buttonequal=new JButton(" = ");

c.add(buttonequal);

buttonequal.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

double temp1,temp2;

double temp=0;

flagsum=0;

temp1=Double.parseDouble(value1);

temp2=Double.parseDouble(value2);

flag=0;

switch(fix)

{

case 1: temp=temp1+temp2;break;

case 2: temp=temp1-temp2;break;

case 3: temp=temp1*temp2;break;

case 4: temp=temp1/temp2;break;

}

result=Double.valueOf(temp).toString();

value1=result;

value2="";

flag=1;

text.setText(result);

}

});

final JButton buttonpoint=new JButton(".");

c.add(buttonpoint);

buttonpoint.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{ if(flagsum==0)

{

String temp;

if(flag==0 )

{

value1=value1+".";

temp=value1;

}

else

{

value2=value2+".";

temp=value2;

}

flagsum=1;

text.setText(temp);

}

}

});

JButton buttonz=new JButton("Start");

c.add(buttonz);

buttonz.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{ if(sum%2==1)

{

happy=true;

text.setText("0.");

flag=0;

}

else

{

happy=false;

value1="";

value2="";

text.setText("");

}

text.setEnabled(happy);

button1.setEnabled(happy);

button2.setEnabled(happy);

button3.setEnabled(happy);

button4.setEnabled(happy);

button5.setEnabled(happy);

button6.setEnabled(happy);

button7.setEnabled(happy);

button8.setEnabled(happy);

button9.setEnabled(happy);

button0.setEnabled(happy);

buttonx.setEnabled(happy);

buttony.setEnabled(happy);

buttonadd.setEnabled(happy);

buttonsubtract.setEnabled(happy);

buttonpoint.setEnabled(happy);

buttonequal.setEnabled(happy);

buttoncheng.setEnabled(happy);

buttonchu.setEnabled(happy);

sum++;

}

});

button1.setEnabled(false);

button2.setEnabled(false);

button3.setEnabled(false);

button4.setEnabled(false);

button5.setEnabled(false);

button6.setEnabled(false);

button7.setEnabled(false);

button8.setEnabled(false);

button9.setEnabled(false);

button0.setEnabled(false);

buttonx.setEnabled(false);

buttony.setEnabled(false);

buttonadd.setEnabled(false);

buttonsubtract.setEnabled(false);

buttonpoint.setEnabled(false);

buttonequal.setEnabled(false);

buttoncheng.setEnabled(false);

buttonchu.setEnabled(false);

text.setEnabled(false);

text.setBounds(20, 20, 200, 40);

buttonx.setBounds(20, 60,100, 40);

buttony.setBounds(140, 60,100, 40);

buttonz.setBounds(260, 60,80, 40);

button1.setBounds(20, 120,60, 40);

button2.setBounds(100, 120,60, 40);

button3.setBounds(180, 120,60, 40);

buttonadd.setBounds(260, 120,60, 40);

button4.setBounds(20, 180,60, 40);

button5.setBounds(100, 180,60, 40);

button6.setBounds(180, 180,60, 40);

buttonsubtract.setBounds(260, 180,60, 40);

button7.setBounds(20, 240,60, 40);

button8.setBounds(100, 240,60, 40);

button9.setBounds(180, 240,60, 40);

buttoncheng.setBounds(260,240,60,40);

button0.setBounds(20, 300,60, 40);

buttonpoint.setBounds(100, 300, 60, 40);

buttonequal.setBounds(180,300,60, 40);

buttonchu.setBounds(260, 300,60, 40);

setVisible(true);

}

class MYMouseEvent extends MouseAdapter

{

public void mousePressed(MouseEvent e)

{

value1=e.toString();

text.setText(value1);

}

}

}

class Calutator

{

public static void main(String[] args)

{

new ConstructFrame();

}

}

你自己慢慢的看吧!

急求大神發(fā)幾個java 300行代碼的小程序 簡單點的

/**

* 文件名:Operation.java 2014-1-2 下午3:06:37

* @author Administrator

*/

package cc.icoc.javaxu.action;

import java.util.ArrayList;

import java.util.Scanner;

import cc.icoc.javaxu.datas.StudentInfo;

/**

* @author 許仕永

* 創(chuàng)建時間: 2014 2014-1-2 下午3:06:37

*/

public class Operation

{

int stuNo,stuAge;

String stuName,stuClass,stuSex;

ArrayListStudentInfo list;

/**程序入口

* @param args

*/

public static void main(String[] args)

{

// TODO Auto-generated method stub

new Operation().operation();

}

private int inputInt()

{

Scanner scanner = new Scanner(System.in);

return scanner.nextInt();

}

private String inputStr()

{

Scanner scanner = new Scanner(System.in);

return scanner.nextLine();

}

private void operation()

{

// TODO Auto-generated method stub

if(list == null)

{

list = new ArrayListStudentInfo();

}

while(true)

{

System.out.println("\t\t\t學生信息管理系統(tǒng)\n");

System.out.println("1.信息查閱");

System.out.println("2.信息查詢");

System.out.println("3.信息錄入");

System.out.println("4.退出系統(tǒng)");

int what = inputInt();

if ( what == 1 )

{

getInfo();

} else if ( what == 2 )

{

allSerach();

} else if ( what == 3 )

{

inputInfo();

} else if( what == 4 )

{

System.out.println("已經(jīng)退出系統(tǒng)");

System.exit(0);

}

}

}

/**

* 獲取全部學生的信息列表

*/

private void getInfo()

{

if(!list.isEmpty())

{

for ( int i = 0; i list.size(); i++ )

{

System.out.println(list.get(i));

}

}

}

/**

* 執(zhí)行查找

*/

private void allSerach()

{

System.out.println("1.輸入學號進行查詢");

System.out.println("2.輸入姓名進行查詢");

int what = inputInt();

if(what == 1)

{

System.out.println("請輸入學號:");

search(inputInt());

}

else

{

System.out.println("請輸入姓名:");

search(inputStr());

}

}

/**

* 按學生姓名查詢學生信息

* @param name 學生姓名

*/

private StudentInfo search(String name)

{

for ( int i = 0; i list.size(); i++ )

{

if(list.get(i).getStuName().equals(name))

{

System.out.println(list.get(i));

return list.get(i);

}

}

System.out.println("未查詢到該名字的學生");

return null;

}

/**

* 按學號查詢學生信息

* @param id 學號

*/

private StudentInfo search(int id)

{

for ( int i = 0; i list.size(); i++ )

{

if(list.get(i).getStuNo()==id)

{

System.out.println(list.get(i));

return list.get(i);

}

}

System.out.println("未查詢到該學號的學生");

return null;

}

/**

* 錄入學生信息

*/

private void inputInfo()

{

try

{

System.out.print("請輸入學生學號:\n");

stuNo = inputInt();

System.out.print("請輸入學生姓名:\n");

stuName = inputStr();

System.out.print("請輸入學生性別:\n");

stuSex = inputStr();

System.out.print("請輸入學生年齡:\n");

stuAge = inputInt();

System.out.print("請輸入學生班級:\n");

stuClass = inputStr();

list.add(new StudentInfo(stuNo, stuAge, stuName, stuSex, stuClass));

} catch (Exception e)

{

// TODO: handle exception

System.out.println("不允許為空,請重新輸入");

}

}

}

package cc.icoc.javaxu.action;

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

public class Stu

{

int countStu = 0;

int sum = 0;

int avg = 0;

ListStuBean list = new ArrayListStu.StuBean();

public static void main(String[] args)

{

new Stu().go();

}

private void go()

{

A:while(true)

{

//構(gòu)造實體Bean來存儲學生成績

StuBean bean = new StuBean();

System.out.println("請輸入成績:");

System.out.println("語文:");

bean.setYuwen(scanner());

System.out.println("數(shù)學:");

bean.setMath(scanner());

//獲取英語成績

System.out.println("英語:");

bean.setEnglish(scanner());

//存入容器

list.add(bean);

for ( int i = 0; i list.size(); i++ )

{

sum += list.get(i).english+list.get(i).math+list.get(i).yuwen;

}

avg = sum / (3*list.size());

System.out.println("當前有"+list.size()+"條學生記錄,所有學生總分="+sum+"平均分為"+avg);

//輸入y繼續(xù)錄入學生信息,輸入x退出

System.out.println("\n已成功錄入一個學生的數(shù)據(jù),是否繼續(xù)/退出(y/x)");

if("x".equals(scannerString()))

break A;

}

}

/**輸入*/

private int scanner()

{

Scanner scanner = new Scanner(System.in);

return scanner.nextInt();

}

/**輸入*/

private String scannerString()

{

Scanner scanner = new Scanner(System.in);

return scanner.nextLine();

}

class StuBean

{

int math;

int yuwen;

int english;

public int getMath()

{

return math;

}

public void setMath(int math)

{

this.math = math;

}

public int getYuwen()

{

return yuwen;

}

public void setYuwen(int yuwen)

{

this.yuwen = yuwen;

}

public int getEnglish()

{

return english;

}

public void setEnglish(int english)

{

this.english = english;

}

}

}

/**

* 文件名:StudentInfo.java 2014-1-2 下午3:07:29

* @author Administrator

*/

package cc.icoc.javaxu.datas;

/**

* @author 許仕永

* 創(chuàng)建時間: 2014 2014-1-2 下午3:07:29

*/

public class StudentInfo

{

int stuNo,stuAge;

String stuName,stuSex,stuClass;

public StudentInfo(int stuNo, int stuAge, String stuName, String stuSex, String stuClass)

{

super();

this.stuNo = stuNo;

this.stuAge = stuAge;

this.stuName = stuName;

this.stuSex = stuSex;

this.stuClass = stuClass;

}

public int getStuNo()

{

return stuNo;

}

public void setStuNo(int stuNo)

{

this.stuNo = stuNo;

}

public int getStuAge()

{

return stuAge;

}

public void setStuAge(int stuAge)

{

this.stuAge = stuAge;

}

public String getStuName()

{

return stuName;

}

public void setStuName(String stuName)

{

this.stuName = stuName;

}

public String getStuSex()

{

return stuSex;

}

public void setStuSex(String stuSex)

{

this.stuSex = stuSex;

}

public String getStuClass()

{

return stuClass;

}

public void setStuClass(String stuClass)

{

this.stuClass = stuClass;

}

@Override

public String toString()

{

// TODO Auto-generated method stub

String s = "學號:"+getStuNo()+"\t姓名:"+getStuName()+" \t性別:"+getStuSex()+"\t年齡:"+getStuAge()+"\t班級:"+getStuClass();

return s;

}

}


當前標題:關(guān)于java300代碼的信息
標題網(wǎng)址:http://weahome.cn/article/hphgch.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部