《JAVA程序设计》考题急求答案,急求java试题简答,java课后习题答案.(拒绝打酱油)

《JAVA程序设计》考题急求答案,急求java试题简答,java课后习题答案.(拒绝打酱油),第1张

对几个容易错的稍微注解下,

1 D

2 C final修饰

3 B

4 B

5 C

6 B

7 C

8 C

9 B JAVA里面都是写作null的,而不是NULL

10 A: Stringsubstring()大小写问题

11 C

12C

13A

14C

15A

16B

17C

18C

19D

20D管道流,此流一般用于多线

(1)。public class TiaoSeBan extends JFrame {

JPanel panel1;

JPanel toppanel;

JPanel bottompanel;

JPanel colorLabpanel;

JPanel colorScrollBarpanel;

JLabel redLable;

JLabel greenLable;

JLabel blueLable;

JLabel showColorLable;

JScrollBar redScrollBar;

JScrollBar greenScrollBar;

JScrollBar blueScrollBar;

void init(){

panel1=new JPanel();

toppanel=new JPanel();

bottompanel=new JPanel();

colorLabpanel=new JPanel();

colorScrollBarpanel=new JPanel();

redLable=new JLabel("Red");

greenLable =new JLabel("Green");

blueLable=new JLabel("Blue");

showColorLable=new JLabel("Show Colors");

redScrollBar =new JScrollBar(JScrollBarHORIZONTAL , 0, 100,0,255);

greenScrollBar =new JScrollBar(JScrollBarHORIZONTAL , 0,100,0,255);

blueScrollBar =new JScrollBar(JScrollBarHORIZONTAL , 0, 100,0,255);

}

TiaoSeBan(){

super();

init();

setLayout(new BorderLayout());

add(toppanel,BorderLayoutCENTER);

add(bottompanel,BorderLayoutSOUTH);

showColorLablesetHorizontalAlignment(SwingConstantsCENTER);

toppanelsetLayout(new BorderLayout());

toppaneladd(showColorLable,BorderLayoutCENTER);

bottompanelsetLayout(new BorderLayout());

bottompaneladd(colorLabpanel,BorderLayoutWEST);

bottompaneladd(colorScrollBarpanel,BorderLayoutCENTER);

colorLabpanelsetLayout(new GridLayout(3, 1));

colorLabpaneladd(redLable);

colorLabpaneladd(greenLable);

colorLabpaneladd(blueLable);

colorScrollBarpanelsetLayout(new GridLayout(3, 1));

colorScrollBarpaneladd(redScrollBar);

colorScrollBarpaneladd(greenScrollBar);

colorScrollBarpaneladd(blueScrollBar);

redScrollBaraddAdjustmentListener(new AdjustmentListener() {

public void adjustmentValueChanged(AdjustmentEvent e) {

reSetColor(showColorLable);

}

});

greenScrollBaraddAdjustmentListener(new AdjustmentListener() {

public void adjustmentValueChanged(AdjustmentEvent e) {

reSetColor(showColorLable);

}

});

blueScrollBaraddAdjustmentListener(new AdjustmentListener() {

public void adjustmentValueChanged(AdjustmentEvent e) {

reSetColor(showColorLable);

}

});

}

void reSetColor(JLabel label){

labelsetForeground(new Color(redScrollBargetValue(), greenScrollBargetValue(), blueScrollBargetValue()));

}

public static void main(String[] args) {

TiaoSeBan frame=new TiaoSeBan();

framesetTitle("tiaoseban");

framesetLocationRelativeTo(null);

framesetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);

framesetSize(200,200);

framesetVisible(true);

}

}

(2)public class jisuanq extends JApplet implements ActionListener {

private JTextField jtf = new JTextField(10);

private boolean newNumber = true;

private int result = 0;

private String op = "=";

public void init() {

JPanel p = new JPanel();

psetLayout(new BorderLayout());

JPanel westPanel = new JPanel();

westPanelsetLayout(new GridLayout(5, 0));

westPaneladd(new JButton(" "));

westPaneladd(new JButton("MC"));

westPaneladd(new JButton("MR"));

westPaneladd(new JButton("MS"));

westPaneladd(new JButton("M+"));

Panel centerPanel = new Panel();

centerPanelsetLayout(new BorderLayout());

Panel p1 = new Panel();

Panel p2 = new Panel();

p1setLayout(new FlowLayout(FlowLayoutRIGHT));

p1add(new JButton("Back"));

p1add(new JButton("CE"));

p1add(new JButton("C"));

p2setLayout(new GridLayout(4, 5));

JButton bt;

p2add(bt = new JButton("7"));

btaddActionListener(this);

p2add(bt = new JButton("8"));

btaddActionListener(this);

p2add(bt = new JButton("9"));

btaddActionListener(this);

p2add(bt = new JButton("/"));

btaddActionListener(this);

p2add(bt = new JButton("sqrt"));

btaddActionListener(this);

p2add(bt = new JButton("4"));

btaddActionListener(this);

p2add(bt = new JButton("5"));

btaddActionListener(this);

p2add(bt = new JButton("6"));

btaddActionListener(this);

p2add(bt = new JButton(""));

btaddActionListener(this);

p2add(bt = new JButton("%"));

btaddActionListener(this);

p2add(bt = new JButton("1"));

btaddActionListener(this);

p2add(bt = new JButton("2"));

btaddActionListener(this);

p2add(bt = new JButton("3"));

btaddActionListener(this);

p2add(bt = new JButton("-"));

btaddActionListener(this);

p2add(bt = new JButton("1/x"));

btaddActionListener(this);

p2add(bt = new JButton("0"));

btaddActionListener(this);

p2add(bt = new JButton("+/-"));

btaddActionListener(this);

p2add(bt = new JButton(""));

p2add(bt = new JButton("+"));

btaddActionListener(this);

p2add(bt = new JButton("="));

btaddActionListener(this);

centerPaneladd(p2, BorderLayoutCENTER);

centerPaneladd(p1, BorderLayoutNORTH);

padd(centerPanel, BorderLayoutCENTER);

padd(westPanel, BorderLayoutWEST);

getContentPane()setLayout(new BorderLayout());

getContentPane()add(p, BorderLayoutCENTER);

getContentPane()add(jtf, BorderLayoutNORTH);

}

public void actionPerformed(ActionEvent e) {

String actionCommand = egetActionCommand();

if ('0' <= actionCommandcharAt(0) &&

actionCommandcharAt(0) <= '9') {

if (newNumber) {

jtfsetText(actionCommand);

newNumber = false;

}

else {

jtfsetText(jtfgetText() + actionCommand);

}

}

else

if (newNumber) {

if (actionCommandequals("-")) {

jtfsetText("-");

newNumber = false;

}

else

op = actionCommand;

}

else {

execute();

op = actionCommand;

}

}

void execute() {

int number = new Integer(jtfgetText())intValue();

Systemoutprintln("number " + op);

switch (opcharAt(0)) {

case '+': result += number; break;

case '-': result -= number; break;

case '': result = number; break;

case '/': result /= number; break;

case '%': result %= number; break;

case '=': result = number;

}

Systemoutprintln("result "+result);

jtfsetText(new Integer(result)toString());

newNumber = true;

}

/This main method enables the applet to run as an application/

public static void main(String[] args) {

// Create a frame

JFrame frame = new JFrame("Exercise16_8");

// Create an instance of the applet

jisuanq applet = new jisuanq();

// Add the applet instance to the frame

framegetContentPane()add(applet, BorderLayoutCENTER);

// Invoke init() and start()

appletinit();

appletstart();

// Display the frame

framesetSize(300, 300);

framesetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);

framesetLocationRelativeTo(null);

framesetVisible(true);

}

}

1:ObjectInputStream ,ObjectOutputStream

2:try{}

3:10

4:多继承

5:new

6:int , char

7:KeyListener

8:Applet

以上答案尽请参考

哥们我给你写完了,耽误了我半个小时的时间啊!你直接运行就可以了

import javaawtBorderLayout;

import javaawtFlowLayout;

import javaawteventActionEvent;

import javaawteventActionListener;

import javautilCalendar;

import javaxswingJButton;

import javaxswingJFrame;

import javaxswingJLabel;

import javaxswingJPanel;

import javaxswingJTextField;

public class Constellation implements ActionListener{

private JFrame frame = null;

private JTextField year = null;

private JTextField month = null;

private JTextField day = null;

private JLabel label1 = null;

private JLabel label2 = null;

private JLabel label3 = null;

private JPanel panel1 = null;

private JPanel panel2 = null;

private JButton button = null;

private JTextField output = null;

public static final String[] zodiacArr = { "猴", "鸡", "狗", "猪", "鼠", "牛", "虎", "兔", "龙", "蛇",

"马", "羊" };

public static final String[] constellationArr = { "水瓶座", "双鱼座", "牡羊座", "金牛座", "双子座", "巨蟹座",

"狮子座", "处女座", "天秤座", "天蝎座", "射手座", "魔羯座" };

public static final int[] constellationEdgeDay = { 20, 19, 21, 21, 21, 22, 23, 23, 23, 23, 22,

22 };

/

根据日期获取生肖

@return 11

/

public static String date2Zodica(Calendar time) {

return zodiacArr[timeget(CalendarYEAR) % 12];

}

/

根据日期获取星座

@param time

@return

/

public static String date2Constellation(Calendar time) {

int month = timeget(CalendarMONTH);

int day = timeget(CalendarDAY_OF_MONTH);

if (day < constellationEdgeDay[month]) {

month = month - 1;

}

if (month >= 0) {

return constellationArr[month];

}

// default to return 魔羯

return constellationArr[11];

}

public Constellation(){

frame = new JFrame("计算生肖,星座");

year = new JTextField("",3);

month = new JTextField("",3);

day = new JTextField("",3);

label1 = new JLabel("请输入年份:");

label2 = new JLabel(",请输入月份:");

label3 = new JLabel(",请输入日期:");

button = new JButton("查看结果");

buttonaddActionListener(this);

panel1 = new JPanel();

panel1setLayout(new FlowLayout(FlowLayoutCENTER));

panel1add(label1);

panel1add(year);

panel1add(label2);

panel1add(month);

panel1add(label3);

panel1add(day);

panel1add(button);

framesetLayout(new BorderLayout());

frameadd(panel1,BorderLayoutNORTH);

panel2 = new JPanel();

output = new JTextField("",40);

panel2add(output,JPanelCENTER_ALIGNMENT);

frameadd(panel2,BorderLayoutCENTER);

framesetSize(500, 100);

framesetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);

framesetVisible(true);

}

public void actionPerformed(ActionEvent e) {

outputsetText("");

int y = IntegerparseInt(yeargetText());

int m = IntegerparseInt(monthgetText());

int d = IntegerparseInt(daygetText());

Calendar calendar = CalendargetInstance();

calendarset(CalendarYEAR, y);

calendarset(CalendarMONTH, m);

calendarset(CalendarDAY_OF_MONTH, d);

String zodica = date2Zodica(calendar);

String constellation = date2Constellation(calendar);

String str = "您输入的日期为:"+y+"年-"+m+"-月"+d+"日,得到的生肖:"+zodica+",星座:"+constellation;

outputsetText(str);

}

//testcode

public static void main(String[] args) {

new Constellation();

}

}

1 新建一个MFC工程, 取名TestTab, 选择Dialog based, 然后Finish

2 删除对话框上默认添加的三个控件 添加Tab Control控件并在Property属性中设置ID为IDC_TABTEST 在More Styles里勾上Bottom 在ClassWizard为其添加关联控件型变量, 变量名为m_ctrtab 类型为CTabCtrl

importjavaio;

importjavaioFile;

importjavaioFileReader;

importjavaioFileWriter;

importjavaioIOException;

publicclassNewTxt{

publicstaticvoidmain(String[]args)throwsIOException{

intn=5;//NN数组

double[][]arr=newdouble[n][n];//插入的数组

double[][]arr2=newdouble[n][n];;//读取出的数组

//数组初始化,随机生成的[0,100)之间的double数

for(inti=0;i

for(intj=0;j

arr[i][j]=Mathrandom()100;

Systemoutprintln(arr[i][j]);

}

}

Filefile=newFile("d:\arraytxt");//存放数组数据的文件

FileWriterout=newFileWriter(file);//文件写入流

//将数组中的数据写入到文件中。每行各数据之间TAB间隔

for(inti=0;i

for(intj=0;j

outwrite(arr[i][j]" ");

}

outwrite("");

}

outclose();

in=new(newFileReader(file));//

Stringline;//一行数据

introw=0;

//逐行读取,并将每个数组放入到数组中

while((line=inreadLine())!=null){

String[]temp=linesplit(" ");

for(intj=0;j

arr2[row][j]=DoubleparseDouble(temp[j]);

}

row;

}

inclose();

//显示读取出的数组

for(inti=0;i

for(intj=0;j

Systemoutprint(arr2[i][j]" ");

}

Systemoutprintln();

}

}

}

以上就是关于《JAVA程序设计》考题急求答案,急求java试题简答,java课后习题答案.(拒绝打酱油)全部的内容,包括:《JAVA程序设计》考题急求答案,急求java试题简答,java课后习题答案.(拒绝打酱油)、Java语言程序设计 基础篇第六版 (Y.Daniel Liang )的,第15 16章的编程题答案、Java语言程序设计,填空题等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/9656130.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-30
下一篇 2023-04-30

发表评论

登录后才能评论

评论列表(0条)

保存