当前位置:首页 » 编程软件 » java考试编程题

java考试编程题

发布时间: 2022-03-02 22:28:25

‘壹’ java编程题,考试中,急求!

public class Circle {
private double radius;//Circle类的成员变量:radius 半径
// Circle类的方法成员:Circle( ) 构造方法,将半径置为1;
public Circle() {
radius=1;
}
// Circle(double r) 构造方法,创建Circle对象时将半径初始化为r;
public Circle(double r) {
radius = r;
}

// double getRadius() 获得圆的半径值
public double getRadius(){
return radius;
}
// double getPerimeter() 获得圆的周长
double getPerimeter(){
return 2*Math.PI*getRadius();
}

// double getArea() 获得圆的面积
public double getArea(){
return Math.PI*getRadius()*getRadius();
}
// void circlePrint() 将圆的半径,周长,面积输出到屏幕
public void circlePrint(){
System.out.println("radius="+getRadius());
System.out.println("Perimeter="+getPerimeter());
System.out.println("Area="+getArea());
}

public static void main(String args[]) {
new Circle().circlePrint();//调用默认的构造函数,如果要对半径赋值,在括号里赋值即可
}

}

‘贰’ JAVA 考试编程题如何编写一个矩形类

用这个肯定可以
public class Rectangle {

private float width;//长
private float height;//宽

public Rectangle(float width, float height){
this.width = width;
this.height = height;
}

//计算周长= (长+宽)*2
public float calcCircle(){
return (width + height) * 2;
}

//计算面积 长*宽
public float calcArea(){
return width * height;
}

public float getHeight() {
return height;
}

public void setHeight(float height) {
this.height = height;
}

public float getWidth() {
return width;
}

public void setWidth(float width) {
this.width = width;
}

}

‘叁’ java考试,求编程题步骤!!!

public class Test1 {
public static void main(String[] args) {
int sum=0;
for (int i = 1; i <=50; i++) {
if(i%2==1){
sum+=i;
}
}
System.out.println("1到50之内奇数和为:"+sum);
}
}
另外一种用while的方法:
public class Test1 {
public static void main(String[] args) {
int sum=0;
int i=1;
while(i<=50){
if(i%2==1){
sum+=i;
}
i++;
}
System.out.println("1到50之内奇数和为:"+sum);
}
}

‘肆’ java面向对象程序设计期末考试编程题!急!!!

===============================第一题==============================
import java.applet.Applet;
import java.awt.Color;
import java.awt.Label;

public class test extends Applet {

private Label label;

@Override
public void init() {
label=new Label("欢迎来到java世界!");
label.setBackground(Color.BLUE);
setBackground(Color.PINK);
add(label);
}

}
===============================第二题==============================
因为没图,所以自己设计的界面..

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class test implements ActionListener {

private JFrame frame;
private JLabel label;
private JTextArea jt;
private JScrollPane jsp;
private JButton show;

public test() {
frame=new JFrame("Test");
label=new JLabel("显示内容");
jt=new JTextArea(10,20);
jsp=new JScrollPane(jt);
show = new JButton("显示给定内容");
JPanel panel=new JPanel();
panel.add(label);
panel.add(show);
frame.add(jsp,BorderLayout.NORTH);
frame.add(panel,BorderLayout.SOUTH);

show.addActionListener(this);
show();

}

public void show(){
frame.setLocation(200, 200);
frame.setSize(300, 260);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}

@Override
public void actionPerformed(ActionEvent e) {
label.setText(jt.getText());
}

public static void main(String[] args) {
new test().show();
}

}

‘伍’ 用JAVA写编程题

import java.util.ArrayList;
import java.util.Collections;

public class TestStudent {

public double getArr(ArrayList<Student> list, String name) {
double sum = 0;
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getName().equals(name)) {
sum = list.get(i).getMathSor() + list.get(i).getJavaSor()
+ list.get(i).getEngSor();
}
}
return sum / 3;
}

public void getHigh(ArrayList<Student> list) {
ArrayList<Double> javaSor = new ArrayList<Double>();
for (int i = 0; i < list.size(); i++) {
javaSor.add(list.get(i).getJavaSor());
}
Collections.sort(javaSor);
System.out.println("java low is " + javaSor.get(0));
System.out.println("java high is " + javaSor.get(list.size() - 1));
System.out.println("-----------------------------------");
ArrayList<Double> mathSor = new ArrayList<Double>();
for (int i = 0; i < list.size(); i++) {
mathSor.add(list.get(i).getMathSor());
}
Collections.sort(mathSor);
System.out.println("math low is " + mathSor.get(0));
System.out.println("math high is " + mathSor.get(list.size() - 1));
System.out.println("-----------------------------------");
ArrayList<Double> engSor = new ArrayList<Double>();
for (int i = 0; i < list.size(); i++) {
engSor.add(list.get(i).getEngSor());
}
Collections.sort(engSor);
System.out.println("eng low is " + engSor.get(0));
System.out.println("eng high is " + engSor.get(list.size() - 1));
}

public static void main(String[] args) {
ArrayList<Student> list = new ArrayList<Student>();
list.add(new Student("01", "B", "boy", 25, 78, 78, 78));
list.add(new Student("02", "A", "boy", 23, 68, 98, 94));
list.add(new Student("03", "R", "girl", 24, 78, 78, 65));
list.add(new Student("04", "Q", "boy", 27, 78, 99, 87));
list.add(new Student("05", "F", "girl", 17, 78, 68, 78));

TestStudent testStudent = new TestStudent();
for (int i = 0; i < 5; i++) {
String name = list.get(i).getName();
double arrSor = testStudent.getArr(list, name);
System.out.println(name + "`s arrSor is " + arrSor);
}
System.out.println("-----------------------------------");
testStudent.getHigh(list);
}
}
=====================================
public class Student {

private String id;
private String name;
private String sex;
private int age;
private double mathSor;
private double javaSor;
private double engSor;

public Student() {
super();
}

public Student(String id, String name, String sex, int age, double mathSor,
double javaSor, double engSor) {
super();
this.id = id;
this.name = name;
this.sex = sex;
this.age = age;
this.mathSor = mathSor;
this.javaSor = javaSor;
this.engSor = engSor;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getSex() {
return sex;
}

public void setSex(String sex) {
this.sex = sex;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public double getMathSor() {
return mathSor;
}

public void setMathSor(double mathSor) {
this.mathSor = mathSor;
}

public double getJavaSor() {
return javaSor;
}

public void setJavaSor(double javaSor) {
this.javaSor = javaSor;
}

public double getEngSor() {
return engSor;
}

public void setEngSor(double engSor) {
this.engSor = engSor;
}

}
============================================
两个类,很简单

‘陆’ JAVA比较经典的考试编程题目有哪些基础的!!

http://zpsailor.javaeye.com/admin/blogs/679770
这是我在准备面试的时候做了点基础编程题目,你可以看看。

‘柒’ 两个JAVA编程的题,考试急用!!!求大神

packagecom.ld.Demo;

importjava.util.Scanner;

publicclassTest01{

publicstaticvoidmain(String[]args){

Scannerscanner=newScanner(System.in);
System.out.println("输入行数:");
intnum=scanner.nextInt();
for(inti=1;i<=num;i++){
for(intk=1;k<=num-i;k++){
System.out.print("");
}
for(intj=0;j<2*(i-1)+1;j++){
System.out.print("*");
}
System.out.println();
}
}

}

运行图片:

‘捌’ JAVA编程题~!考试用~!~急急

哦转眼又到放暑假的时候了!看你那么急给你写个吧:写两个类一个main方法测试类
Goods为商品类SupperMacket为超市类
package cn.test.suppermacket.pojo;
public class Goods {
private String name; //商品名
private double price; //价钱
private int number; //产品数量
private int sale; //记录商品余下安全数
private String add; //标记产品是否上架 Y为上架N为未上架
private String showMe; //产品相关信息
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public int getSale() {
return sale;
}
public void setSale(int sale) {
this.sale = sale;
}
public String getAdd() {
return add;
}
public void setAdd(String add) {
this.add = add;
}
public String getShowMe() {
return showMe;
}
public void setShowMe(String showMe) {
this.showMe = showMe;
}
}
----------------------------------------------------SupperMacket类-------------------------------------------------------------------------
package cn.test.suppermacket;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import cn.test.suppermacket.pojo.Goods;
public class SupperMacket {
private Goods goods;
private Map<String,Goods> macket=new HashMap<String,Goods>();
public Goods getGoods() {
return goods;
}

public void setGoods(Goods goods) {
this.goods = goods;
}
public boolean append(Goods goods)
{
if(macket.get(goods.getName())!=null)
{
macket.get(goods.getName()).setNumber(macket.get(goods.getName()).getNumber()+1);
}else
{
goods.setNumber(1);
macket.put(goods.getName(), goods);
}
return true;
}
public boolean delete(String name)
{
if(macket.get(name)!=null)
{
if(macket.get(name).getNumber()==0)
{
System.out.println("已经没货了还不快去进货!");
macket.get(name).setNumber(1);
}
macket.get(name).setNumber(macket.get(name).getNumber()-1);
}else
{
System.out.println("没有这种商品!");
}
return true;
}
public void query()
{
if(macket.size()>0)
{
Iterator iter=macket.values().iterator();
for(int i=0;i<macket.size();i++)
{
Goods emp=(Goods) iter.next();
System.out.println("|-商品名-:"+emp.getName());
System.out.println("|----价钱:¥"+emp.getPrice());
System.out.println("|----数量:"+emp.getNumber());
System.out.println("|----上架情况-"+("Y".equals(emp.getAdd())?"已上架":"未上架"));
System.out.println("|----商品信息-"+emp.getShowMe());
System.out.println("----------------------------------------------------------");
}
}else
{
System.out.println("超市什么都没有了!");
}
}
public void doSale(String name)
{
if(macket.get(name)!=null)
{
if(macket.get(name).getNumber()<2)
{
System.out.println(macket.get(name).getName()+"最后一件售出了!");
if(macket.get(name).getNumber()==0)
{
System.out.println("已经没货了还不快去进货!");
macket.get(name).setNumber(1);
}
}
macket.get(name).setNumber(macket.get(name).getNumber()-1);
}else
{
System.out.println("没有这种商品!");
}
}
public void doAdd(String name)
{
if(macket.get(name)!=null)
{
if("Y".equals(macket.get(name).getAdd()))
{
System.out.println(macket.get(name).getName()+"已经上架");
}else
{
macket.get(name).setAdd("Y");
}
}
}
public boolean findGoods(String name)
{
if(macket.get(name)!=null)
{
return true;
}
return false;
}
}
------------------------------------------------------main主调方法类--------------------------------------------------------------------------------
package cn.test.test;
import java.util.Scanner;
import cn.test.suppermacket.SupperMacket;
import cn.test.suppermacket.pojo.Goods;
public class DemoTest {
public static void main(String[] args) {
SupperMacket macket=new SupperMacket();
Scanner sc = new Scanner(System.in);
showMune(sc,macket);
}
public static void showMune(Scanner sc,SupperMacket macket){
while(true){
System.out.println("***********************************");
System.out.println("**********超市测试菜单**************");
System.out.println("***(1)增加新的商品******************");
System.out.println("***(2)减少已有商品******************");
System.out.println("***(3)现有商品列表******************");
System.out.println("***(4)商品货物出售******************");
System.out.println("***(5)商品上架操作******************");
System.out.println("请输入你要的操作序号(1-5):");
int i=sc.nextInt();
switch(i){
case 1:
Goods goods=new Goods();
makeGoods(goods,sc,macket);
macket.append(goods);
break;
case 2:
System.out.println("请输入要减少的商品名称:");
String name=sc.next();
macket.delete(name);
break;
case 3:
macket.query();
break;
case 4:
System.out.println("请输入要出售的商品名称:");
name=sc.next();
macket.doSale(name);
break;
case 5:
System.out.println("将商品标记为上架:");
name=sc.next();
macket.doAdd(name);
break;
}
}
}
public static Goods makeGoods(Goods goods,Scanner sc,SupperMacket macket)
{
System.out.println("请输入要添加的商品名称:");
goods.setName(sc.next());
String name=goods.getName();
if(macket.findGoods(name))
{
return goods;
}
System.out.println("请输入商品的价钱");
goods.setPrice(sc.nextDouble());
System.out.println("请输入产品的相关信息~");
goods.setShowMe(sc.next());
return goods;
}
}

热点内容
游戏下载配置失败怎么解决 发布:2025-01-19 14:39:36 浏览:559
微信上的电影怎么下载或缓存 发布:2025-01-19 14:30:57 浏览:826
如何在外网访问服务器 发布:2025-01-19 14:29:45 浏览:380
百度重定向脚本 发布:2025-01-19 14:29:36 浏览:428
php怎么反编译 发布:2025-01-19 14:10:54 浏览:590
加密货币交易平台排名 发布:2025-01-19 13:58:21 浏览:741
红绿灯的编程 发布:2025-01-19 13:57:37 浏览:113
老男孩linux教程 发布:2025-01-19 13:44:48 浏览:941
买车怎么区分车配置 发布:2025-01-19 13:44:45 浏览:242
丢失缓存视频 发布:2025-01-19 13:44:09 浏览:183