「java期末题」java期末考试题及答案简答题
本篇文章给大家谈谈java期末题,以及java期末考试题及答案简答题对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
java期末考试题
单击出现你好的我倒还知道点
package example;
import java.awt.BorderLayout;
public class Switch extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Switch frame = new Switch();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Switch() {
final String string = "你好";
final String string2 = "再见";
setTitle("\u5207\u6362\u6807\u7B7E\u5185\u5BB9");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
final JLabel label = new JLabel(string);
label.setFont(new Font("宋体",Font.BOLD,25));
JButton button = new JButton("\u786E\u5B9A");
button.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (label.getText().equals(string)) {
label.setText(string2);
}
else if (label.getText().equals(string2)) {
label.setText(string);
}
}
});
GroupLayout groupLayout = new GroupLayout(contentPane);
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(153, 153, 153)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addComponent(button)
.addComponent(label))
.addContainerGap(222, Short.MAX_VALUE))
);
groupLayout.setVerticalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(80, 80, 80)
.addComponent(label)
.addGap(38, 38, 38)
.addComponent(button)
.addContainerGap(100, Short.MAX_VALUE))
);
contentPane.setLayout(groupLayout);
}
}
请教四个java期末试题
1、实现1/1+1/2+1/3+...+1/100
2、输入10个数,然后输出
3、建立一个名为'按钮'的Frame
4、求最大值
java期末题,急
public class StudentXW extends Student{
String responsibility;
//
构造方法
public StudentXW(){
super();
//responsibility="";
}
public
StudentBZ(String
aid,String
aname,float
ascoreOfenglish,float
ascoreOfmath,float
ascoreOfcomputer,String aresponsibility){
super(aid,aname,ascoreOfenglish,ascoreOfmath,ascoreOfcomputer);
responsibility=aresponsibility;
}
//testScore
测评成绩
/
平均分
public float testScore(){
return(this.scoreOfsum/3+5);
}
//toString
方法
public String toString(){
return("
学
号
:
"+this.id+"\n
姓
名
:
"+name+"\n
英
语
:
"+this.scoreOfenglish+"\n
数
学
:
"+this.scoreOfmath+"\n
计算机:
"+this.scoreOfcomputer+"\n
总分:
"+this.scoreOfsum+"\n
职
位:
"+this.responsibility);
}
}
做一个简单的Java作业,大二期末作业
第一题直接上网搜java计算器,你想自己写也无所谓,不是多么难的事。第二题属于开放题类,你可以参考游戏中角色的属性值,比如说饱食度、血量之类的属性,六个知识点就更简单了,重载和抛异常就不说了,随便写一个继承类实现一个接口就能体现出重写、继承、接口。最后剩下一个你可以挑一个你比较熟悉的就行了,不建议选多线程,特别容易出问题,不管是正则还是文件流都是很容易体现的
Java 期末编程题
import java.util.Arrays;
import java.util.Scanner;
public class Test
{
private static void p1 ()
{
Scanner sc = new Scanner (System.in);
System.out.println ("从键盘上输入一年份,判断是否为闰年");
int year = sc.nextInt ();
sc.close ();
if (year % 400 == 0 || year % 4 == 0 year % 100 != 0)
{
System.out.println ("是闰年");
}
else
{
System.out.println ("不是闰年");
}
}
private static long p2 ( int n )
{
if (n == 11)
{
return 0;
}
long sum = 1;
for ( int i = 1; i = n; i++ )
{
sum *= i;
}
return sum + p2 (n + 1);
}
private static int p3 ()
{
int sum = 0;
for ( int i = 100; i 201; i++ )
{
boolean yes = true;
for ( int j = 2; j i / 2; j++ )
{
if (i % j == 0)
{
yes = false;
break;
}
}
if (yes)
{
sum += i;
}
}
return sum;
}
private static int p4 ( int n )
{
if (n == 1 || n == 2)
{
return 1;
}
else
{
return p4 (n - 2) + p4 (n - 1);
}
}
private static void p5 ()
{
int[] arr = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 19 };
int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;
for ( int i = 0; i arr.length; i++ )
{
int ai = arr[i];
if (ai max)
{
max = ai;
}
if (ai min)
{
min = ai;
}
}
System.out.println ("最大值:" + max + ", 最小值: " + min);
}
private static void p6 ( int n )
{
int[][] arr = new int[n][];
for ( int i = 0; i arr.length; i++ )
{
arr[i] = new int[i + 1];
for ( int j = 0; j i + 1; j++ )
{
if (j == 0 || j == i)
{
arr[i][j] = 1;
}
else if (i 0 j 0)
{
arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j];
}
}
}
String result = Arrays.deepToString (arr).replaceAll ("[\\[]", "").replaceAll ("\\],\\s", "\r\n").replaceAll ("[,\\]]", "");
System.out.println (result);
}
class P7
{
public int add ( int a, int b )
{
return a + b;
}
public float add ( float a, float b )
{
return a + b;
}
public double add ( double a, double b )
{
return a + b;
}
}
static class Student
{
long id;
String name;
boolean sex;
String phone;
float score;
Student ( long i, String n, boolean s, String p, float sc )
{
this.id = i;
this.name = n;
this.sex = s;
this.phone = p;
this.score = sc;
}
boolean getSex ()
{
return sex;
}
String getPhone ()
{
return phone;
}
float getScore ()
{
return score;
}
@Override
public String toString ()
{
return String.format ("Student [id=%s, name=%s, sex=%s, phone=%s, score=%s]", id, name, sex, phone, score);
}
}
public static void main ( String[] args )
{
p1 ();
System.out.println (p2 (10));
p3 ();
p4 (30);
p5 ();
p6 (10);
Student student = new Student (1000, "YUGI", true, "15878787878", 100);
System.out.println (student.getSex ());
System.out.println (student.getPhone ());
System.out.println (student.getScore ());
System.out.println (student.toString ());
}
}
关于java期末题和java期末考试题及答案简答题的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
发布于:2022-11-28,除非注明,否则均为
原创文章,转载请注明出处。