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

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

java大學考試常用代碼,java大學考試常用代碼大全

java考試,求編程題步驟?。?!

題目一:

為永定等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計制作服務(wù),及永定網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為網(wǎng)站制作、成都做網(wǎng)站、永定網(wǎng)站設(shè)計,以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達到每一位用戶的要求,就會得到認可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!

參考代碼

import?java.util.Scanner;

public?class?JiaFaDemo?{

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

int?x?=?(int)?(Math.random()?*?100);

int?y?=?(int)?(Math.random()?*?100);

System.out.println(x+"+"+y+"="+(x+y));//自動答題??58+4=62

//??System.out.print(x+"+"+y+"=");//人工輸入答題?需要導入包import?java.util.Scanner;

//??Scanner?input?=?new?Scanner(System.in);

//??int?z?=?input.nextInt();

//??if(z==(x+y)){

//???System.out.println("回答正確");

//??}else{

//???System.out.println("回答錯誤");

//??}

}

}

輸出

58+4=62

題目二

public?class?JiShuDemo?{

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

int?sum?=?0;

for?(int?i?=?1;?i?=?50;?i++)?{

if(i%2!=0){//不能被2整除的數(shù)是奇數(shù)

sum+=i;

}

}

System.out.println("1~50間奇數(shù)和="+sum);

}

}

輸出

1~50間奇數(shù)和=625

跪求簡單計算器的java代碼,要入門級的編程~~

//////////////////////////這個很簡單,方法也差不多////////////////////

import javax.swing.*;

import java.awt.event.*;

import java.awt.*;

public class Calculator extends JFrame implements ActionListener

{

///////////////菜單

JMenuBar mb;

JMenu mEdit,mFind,mHelp;

JMenuItem mEditCopy,mEditPaste;

JMenuItem mFindStandarded,mFindScience,mFindGroup;

JMenuItem mHelpTopic,mHelpAbout;

JPanel pan;

/////////////按鈕

JTextField tf;

JButton butnull;

JButton butBackspace,butCE,butC;

JButton butMC,butMR,butMS,butM;

JButton but1,but2,but3,but4,but5,but6,but7,but8,but9,but0;

JButton butChu,butSqrt,butCheng,butYu,butJian,but1x,butDot,butJia,butEqual,butJJ;

Calculator()

{

mb =new JMenuBar();

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

mEdit.setMnemonic('E');

mFind =new JMenu("查看(F)");

mFind.setMnemonic('F');

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

mFind.setMnemonic('H');

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

mEditCopy.setMnemonic('C');

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

mEditCopy.setMnemonic('P');

mFindStandarded=new JMenuItem("標準型(T)");

mFindStandarded.setMnemonic('T');

mFindScience=new JMenuItem("科學型(S)");

mFindScience.setMnemonic('S');

mFindGroup =new JMenuItem("數(shù)字分組(I)");

mFindGroup.setMnemonic('I');

mHelpTopic =new JMenuItem("幫助主題(H)");

mHelpTopic.setMnemonic('H');

mHelpAbout =new JMenuItem("關(guān)于我們(A)");

mHelpAbout.setMnemonic('A');

////////////////////////////添加mb組件beginning

mb.add(mEdit);

mb.add(mFind);

mb.add(mHelp);

mEdit.add(mEditCopy);

mEdit.add(mEditPaste);

mFind.add(mFindStandarded);

mFind.add(mFindScience);

mFind.add(mFindGroup);

mHelp.add(mHelpTopic);

mHelp.add(mHelpAbout);//////////////ending

////////////////////////***創(chuàng)建計算機按鈕***////////////////////

Color red =new Color(250,0,0);

Color green =new Color(0,127,0);

butnull =new JButton("?");

butnull.setForeground(red);

butnull.addActionListener(this);

butBackspace =new JButton("Backspace");

butBackspace.setForeground(green);

butCE =new JButton("CE");

butCE.setForeground(green);

butC =new JButton("C");

butC.addActionListener(this);

butC.setForeground(red);

butMC =new JButton("MC");

butMC.setForeground(green);

butMR =new JButton("MR");

butMR.setForeground(green);

butMS =new JButton("MS");

butMS.setForeground(green);

butM =new JButton("M+");

butM.setForeground(green);

butChu =new JButton("/");

butChu.addActionListener(this);

butChu.setForeground(red);

butCheng =new JButton("*");

butCheng.addActionListener(this);

butCheng.setForeground(red);

butJian =new JButton("-");

butJian.addActionListener(this);

butJian.setForeground(red);

butJia =new JButton("+");

butJia.addActionListener(this);

butJia.setForeground(red);

butEqual =new JButton("=");

butEqual.addActionListener(this);

butEqual.setForeground(red);

Color blue =new Color(0,0,250);

butSqrt =new JButton("sqrt");

butSqrt.setForeground(green);

butYu =new JButton("%");

butYu.setForeground(green);

but1x =new JButton("1/x");

but1x.setForeground(green);

butDot =new JButton(".");

butDot.setForeground(blue);

butDot.addActionListener(this);

butJJ =new JButton("+/-");

butJJ.setForeground(blue);

butJJ.addActionListener(this);

but1 =new JButton("1");

but1.addActionListener(this);

but1.setForeground(blue);

but2 =new JButton("2");

but2.addActionListener(this);

but2.setForeground(blue);

but3 =new JButton("3");

but3.addActionListener(this);

but3.setForeground(blue);

but4 =new JButton("4");

but4.addActionListener(this);

but4.setForeground(blue);

but5 =new JButton("5");

but5.addActionListener(this);

but5.setForeground(blue);

but6 =new JButton("6");

but6.addActionListener(this);

but6.setForeground(blue);

but7 =new JButton("7");

but7.addActionListener(this);

but7.setForeground(blue);

but8 =new JButton("8");

but8.addActionListener(this);

but8.setForeground(blue);

but9 =new JButton("9");

but9.addActionListener(this);

but9.setForeground(blue);

but0 =new JButton("0");

but0.addActionListener(this);

but0.setForeground(blue);///////////////////////////////ending

pan =new JPanel(null);//創(chuàng)建最大的panel

tf =new JTextField("0");//輸入顯示框

tf.setBounds(5,0,337,25);//顯示框設(shè)置大小位置

tf.setBackground(Color.white);

tf.setHorizontalAlignment(JTextField.RIGHT);//輸入框設(shè)置位子居右顯示

tf.setEditable(false);

JPanel pa=new JPanel(new BorderLayout());//所有按鈕的panel

pa.setBounds(5,35,340,240);

JPanel pp=new JPanel(new BorderLayout());//null,MC,MR,MS,M+的panel;pa的西

JPanel aa=new JPanel(new BorderLayout());//其余所有Button的panel;pa的中

JPanel p =new JPanel(new GridLayout(4,1));//MC,MR,MS,M+的Panel,pp的中 北是一個butnull

JPanel a =new JPanel(new GridLayout(1,3));//backspace,ce,c的panel,aa的北

JPanel a2=new JPanel(new GridLayout(4,5));//其余的button的panel,aa的中

pa.add(pp,BorderLayout.WEST);

pa.add(aa,BorderLayout.CENTER);

pp.add(butnull,BorderLayout.NORTH);

pp.add(p,BorderLayout.CENTER);

p.add(butMC);

p.add(butMR);

p.add(butMS);

p.add(butM);

aa.add(a,BorderLayout.NORTH);

aa.add(a2,BorderLayout.CENTER);

a.add(butBackspace);

a.add(butCE);

a.add(butC);

a2.add(but7);

a2.add(but8);

a2.add(but9);

a2.add(butChu);

a2.add(butSqrt);

a2.add(but4);

a2.add(but5);

a2.add(but6);

a2.add(butCheng);

a2.add(butYu);

a2.add(but1);

a2.add(but2);

a2.add(but3);

a2.add(butJian);

a2.add(but1x);

a2.add(but0);

a2.add(butJJ);

a2.add(butDot);

a2.add(butJia);

a2.add(butEqual);

this.add(pan);

pan.add(tf);

pan.add(pa);

this.setTitle("我的計算器");

this.setJMenuBar(mb);

this.setBounds(200,300,353,330);//設(shè)置窗口大小

this.setResizable(false);

this.setVisible(true);

}

public static void main(String args[])

{

try

{

UIManager.setLookAndFeel(

UIManager.getSystemLookAndFeelClassName());

}

catch (Exception ex)

{

ex.printStackTrace();

}

new Calculator();

}

////////////////////********以下是監(jiān)聽設(shè)置和運算*******///////////////////

boolean b=true;//初始值設(shè)置為真未點運算符號

String fuhao="";//保存最后一次運算符號,用于進行上次結(jié)果的運算

String lastCommand="";//保存按等號前的最后的運算符號

double lastValue=0.0;//保存按等號錢的最后的輸入框里的值

double value=0.0;//原值,當你點完運算符的時候計算之前的值

double fuzhi=0.0;

public void actionPerformed(ActionEvent click)/////////////////////行為監(jiān)聽設(shè)置

{

if(click.getSource()==butJJ)

{

fuzhi=Double.parseDouble(tf.getText());

if(tf.getText().equals("0")||tf.getText().equals("0."))

{

boolean b=true;

String fuhao="";

double value=0.0;

tf.setText("0");

}

else if(fuzhi0)

{

tf.setText((-fuzhi)+"");

}

else

{

tf.setText("-"+tf.getText());

}

}

if(click.getSource()==butnull)

{

tf.setText("本計算器版權(quán)所有歸青軟培訓--胡迅--2008年10月18日著 ");

}

if(click.getSource()==butC)

{

tf.setText("0");

lastCommand="";

lastValue=0.0;

b=true;

fuhao="";

value=0.0;

}

if(click.getSource()==but1)

{

if(b==false)

{

tf.setText("1");

b=true;

}

else if(tf.getText().equals("0"))

{

tf.setText("1");

}

else

{

tf.setText(tf.getText()+1);

}

}

if(click.getSource()==but2)

{

if(b==false)

{

tf.setText("2");

b=true;

}

else if(tf.getText().equals("0"))

{

tf.setText("2");

}

else

{

tf.setText(tf.getText()+2);

}

}

if(click.getSource()==but3)

{

if(b==false)

{

tf.setText("3");

b=true;

}

else if(tf.getText().equals("0"))

{

tf.setText("3");

}

else

{

tf.setText(tf.getText()+3);

}

}

if(click.getSource()==but4)

{

if(b==false)

{

tf.setText("4");

b=true;

}

else if(tf.getText().equals("0"))

{

tf.setText("4");

}

else

{

tf.setText(tf.getText()+4);

}

}

if(click.getSource()==but5)

{

if(b==false)

{

tf.setText("5");

b=true;

}

else if(tf.getText().equals("0"))

{

tf.setText("5");

}

else

{

tf.setText(tf.getText()+5);

}

}

if(click.getSource()==but6)

{

if(b==false)

{

tf.setText("6");

b=true;

}

else if(tf.getText().equals("0"))

{

tf.setText("6");

}

else

{

tf.setText(tf.getText()+6);

}

}

if(click.getSource()==but7)

{

if(b==false)

{

tf.setText("7");

b=true;

}

else if(tf.getText().equals("0"))

{

tf.setText("7");

}

else

{

tf.setText(tf.getText()+7);

}

}

if(click.getSource()==but8)

{

if(b==false)

{

tf.setText("8");

b=true;

}

else if(tf.getText().equals("0"))

{

tf.setText("8");

}

else

{

tf.setText(tf.getText()+8);

}

}

if(click.getSource()==but9)

{

if(b==false)

{

tf.setText("9");

b=true;

}

else if(tf.getText().equals("0"))

{

tf.setText("9");

}

else

{

tf.setText(tf.getText()+9);

}

}

if(click.getSource()==but0)

{

if(b==false)

{

tf.setText("0");

b=true;

}

else if(tf.getText().equals("0"))

{

tf.setText("0");

}

else

{

tf.setText(tf.getText()+0);

}

}

if(click.getSource()==butDot)

{

/////////code/////////////////////////////////////////////////////////////////////////////////////////////////////////???

int izhi=Integer.parseInt(tf.getText());

double dzhi=Double.parseDouble(tf.getText());

if(tf.getText().equals("0"))

{

tf.setText("0.");

}

else

{

if(tf.getText().equals("0."))

{

tf.setText("0.");

}

else

{

if(dzhi0)

{

izhi=izhi;

dzhi=dzhi;

if(dzhi==izhi)

{

tf.setText(tf.getText()+".");

}

}

else

{

izhi=-izhi;

dzhi=-dzhi;

if(dzhi==izhi)

{

tf.setText(tf.getText()+".");

}

}

}

}

}

if(click.getSource()==butJia)///////////////////////////////////////////////"+"

{

if(tf.getText().equals("0"))

{

}

else if(fuhao=="")

{

double tfvaluejia;

tfvaluejia=Double.parseDouble(tf.getText());

value=tfvaluejia;

tf.setText(""+value);

b=false;

fuhao="+";

}

else if(fuhao=="*")

{

double tfvalueCheng;

tfvalueCheng=Double.parseDouble(tf.getText());

value=value*tfvalueCheng;

tf.setText(""+value);

b=false;

}

else if(fuhao=="/")

{

double tfvalueChu;

tfvalueChu=Double.parseDouble(tf.getText());

value=value/tfvalueChu;

tf.setText(""+value);

b=false;

}

else if(fuhao=="-")

{

double tfvaluejian;

tfvaluejian=Double.parseDouble(tf.getText());

value=value-tfvaluejian;

tf.setText(""+value);

b=false;

}

else if(fuhao=="=")

{

double tfvaluejia;

tfvaluejia=Double.parseDouble(tf.getText());

value=tfvaluejia;

b=false;

}

else

{

double tfvaluejia;

tfvaluejia=Double.parseDouble(tf.getText());//2

value=value+tfvaluejia;

tf.setText(""+value);

b=false;

}

lastValue=Double.parseDouble(tf.getText());

fuhao="+";

lastCommand="+";

}

if(click.getSource()==butCheng)////////////////////////////////////////////////////////////"*"

{

if(tf.getText().equals("0"))

{

}

else if(fuhao=="")

{

double tfvalueCheng;

tfvalueCheng=Double.parseDouble(tf.getText());

value=tfvalueCheng;

tf.setText(""+value);

b=false;

fuhao="*";

}

else if(fuhao=="+")

{

double tfvaluejia;

tfvaluejia=Double.parseDouble(tf.getText());

value=value+tfvaluejia;

tf.setText(""+value);

b=false;

}

else if(fuhao=="/")

{

double tfvalueChu;

tfvalueChu=Double.parseDouble(tf.getText());

value=value/tfvalueChu;

tf.setText(""+value);

b=false;

}

else if(fuhao=="-")

{

double tfvaluejian;

tfvaluejian=Double.parseDouble(tf.getText());

value=value-tfvaluejian;

tf.setText(""+value);

b=false;

}

else if(fuhao=="=")

{

double tfvalueCheng;

tfvalueCheng=Double.parseDouble(tf.getText());

value=tfvalueCheng;

b=false;

}

else

{

double tfvalueCheng;

tfvalueCheng=Double.parseDouble(tf.getText());

value=value*tfvalueCheng;

tf.setText(""+value);

b=false;

}

lastValue=Double.parseDouble(tf.getText());

fuhao="*";

lastCommand="*";

}

if(click.getSource()==butChu)//////////////////////////////////////////////"/"

{

if(tf.getText().equals("0"))

{

}

else if(fuhao=="")

{

double tfvalueChu;

tfvalueChu=Double.parseDouble(tf.getText());

value=tfvalueChu;

tf.setText(""+value);

b=false;

fuhao="/";

}

else if(fuhao=="+")

{

double tfvaluejia;

tfvaluejia=Double.parseDouble(tf.getText());

value=value+tfvaluejia;

tf.setText(""+value);

b=false;

}

else if(fuhao=="*")

{

double tfvalueCheng;

tfvalueCheng=Double.parseDouble(tf.getText());

value=value*tfvalueCheng;

tf.setText(""+value);

b=false;

}

else if(fuhao=="-")

{

double tfvaluejian;

tfvaluejian=Double.parseDouble(tf.getText());

value=value-tfvaluejian;

tf.setText(""+value);

b=false;

}

else if(fuhao=="=")

{

double tfvalueCheng;

tfvalueCheng=Double.parseDouble(tf.getText());

value=tfvalueCheng;

b=false;

}

else

{

double tfvalueChu;

tfvalueChu=Double.parseDouble(tf.getText());

value=value/tfvalueChu;

tf.setText(""+value);

b=false;

}

lastValue=Double.parseDouble(tf.getText());

fuhao="/";

lastCommand="/";

}

if(click.getSource()==butJian)////////////////////////////////////////////////////////////////////////"-"

{

if(tf.getText().equals("0"))

{

}

else if(fuhao=="")

{

double tfvaluejian;

tfvaluejian=Double.parseDouble(tf.getText());

value=tfvaluejian;

tf.setText(""+value);

b=false;

fuhao="/";

}

else if(fuhao=="+")

{

double tfvaluejia;

tfvaluejia=Double.parseDouble(tf.getText());

value=value+tfvaluejia;

tf.setText(""+value);

b=false;

}

else if(fuhao=="*")

{

double tfvalueCheng;

tfvalueCheng=Double.parseDouble(tf.getText());

value=value*tfvalueCheng;

tf.setText(""+value);

b=false;

}

else if(fuhao=="/")

{

double tfvalueChu;

tfvalueChu=Double.parseDouble(tf.getText());

value=value/tfvalueChu;

tf.setText(""+value);

b=false;

}

else if(fuhao=="=")

{

double tfvalueCheng;

tfvalueCheng=Double.parseDouble(tf.getText());

value=tfvalueCheng;

b=false;

}

else

{

double tfvaluejian;

tfvaluejian=Double.parseDouble(tf.getText());

value=value-tfvaluejian;

tf.setText(""+value);

b=false;

}

lastValue=Double.parseDouble(tf.getText());

fuhao="-";

lastCommand="-";

}

if(click.getSource()==butEqual)//////////////////////////////////////////"="

{

if(tf.getText().equals("0"))

{

}

if(fuhao=="+")

{

double tfvaluejia;

tfvaluejia=Double.parseDouble(tf.getText());

value=value+tfvaluejia;

tf.setText(""+value);

b=false;

}

else if(fuhao=="*")

{

double tfvalueCheng;

tfvalueCheng=Double.parseDouble(tf.getText());

value=value*tfvalueCheng;

tf.setText(""+value);

b=false;

}

else if(fuhao=="/")

{

double tfvalueChu;

tfvalueChu=Double.parseDouble(tf.getText());

value=value/tfvalueChu;

tf.setText(""+value);

b=false;

}

else if(fuhao=="-")

{

double tfvaluejian;

tfvaluejian=Double.parseDouble(tf.getText());

value=value-tfvaluejian;

tf.setText(""+value);

b=false;

}

else if(fuhao=="=")

{

if(lastCommand=="+")

{

value = value +lastValue;

tf.setText(""+value);

b=false;

}

else if(lastCommand=="-")

{

value = value - lastValue;

tf.setText(""+value);

b=false;

}

if(lastCommand=="*")

{

value = value *lastValue;

tf.setText(""+value);

b=false;

}

if(lastCommand=="/")

{

value = value /lastValue;

tf.setText(""+value);

b=false;

}

}

fuhao="=";

}

}

}

大學JAVA選修考試求大神

樓主,程序如下:

題目1:

public class Student {

private String name; //姓名

private int sno; //學號

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getSno() {

return sno;

}

public void setSno(int sno) {

this.sno = sno;

}

}

=========================華麗的分割線===========================

題目2:

public class Student implements ComparableStudent{

private String name; //姓名

private int sno; //學號

private float score;

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getSno() {

return sno;

}

public void setSno(int sno) {

this.sno = sno;

}

public float getScore() {

return score;

}

public void setScore(float score) {

this.score = score;

}

public int compareTo(Student o) {

if(this == o)

{

return 0;

}

if(this.score o.score)

{

return 1;

}

else if(this.score o.score)

{

return -1;

}

else

{

return 0;

}

}

}

=========================華麗的分割線===========================

題目3:

import java.util.Calendar;

import java.util.GregorianCalendar;

public class HelloDuke {

public static void main(String[] args) {

Calendar calendar = new GregorianCalendar();

int hour = calendar.get(Calendar.HOUR_OF_DAY);

if(hour 12)

{

System.out.println("上午好");

}

else if(hour 13)

{

System.out.println("中午好");

}

else if(hour 18)

{

System.out.println("下午好");

}else

{

System.out.println("晚上好");

}

}

}

有問題歡迎提問,滿意請采納!

Java實驗,代碼怎么寫?

Shape.java接口代碼

public interface Shape {

public static final double PI = 3.14d;

public double area();

}

Circle.java圓類代碼

public class Circle implements Shape {

private double radius;

public Circle(double radius) {

? this.radius = radius;

}

@Override

public double area() {

? return PI * this.radius * this.radius;

}

public double perimeter() {

? return 2 * PI * this.radius;

}

}

Cylinder.java圓柱體類代碼

public class Cylinder extends Circle {

private double height;

public Cylinder(double radius, double height) {

? super(radius);

? this.height = height;

}

public double area() {

? return 2 * super.area() + super.perimeter() * this.height;

}

public double volume() {

? return super.area() * this.height;

}

}

X5_3_6.java主類代碼

public class X5_3_6 {

public static void main(String[] args) {

? Circle cir1 = new Circle(5);

? System.out.println("圓的面積為:" + cir1.area());

? System.out.println("圓的周長為:" + cir1.perimeter());

? Cylinder cy1 = new Cylinder(10, 15);

? System.out.println("圓柱體的表面積為:" + cy1.area());

? System.out.println("圓柱體的體積為:" + cy1.volume());

}

}

上面是我寫的代碼,下圖是執(zhí)行結(jié)果,麻煩看一下,是否可以。


名稱欄目:java大學考試常用代碼,java大學考試常用代碼大全
標題來源:http://weahome.cn/article/dscjdij.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部