「大一java考试编程题」Java编程试题

博主:adminadmin 2022-11-21 18:29:11 67

本篇文章给大家谈谈大一java考试编程题,以及Java编程试题对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

java编程题目,明天考试用,急啊!!

第一题代码太多了,这里不方便写了

第二题还是比较简单,只需要针对字符串每个字符遍历(String.length),当然题目里面要求用while循环,否则直接用一个方法就可以了。当然还是需要统计转换的个数。这里给你写个主要的内容吧,其他自己写。

int i=0;

int count=0;

string str1;

while (istr.length)

{

if (str.indexOf(i)=97 str.indexOf(i)=123)

{

str1+=str.indexOf(i)-32;//这个地方不好,但是对于这个题目没关系

count++;

}

else

{

str1+=str.indexOf(i);

}

}

第三题也不难,会定义数组就一定会,但是这个里面也有问题,应为JAVA从键盘里读入数据,好像没那么简单,不过,这个题目里面,这部分不写也不会有太大问题。

public class Test

{

public static void main(string[] args)

{

int count= convert(args);//转换成数值

String[] num=new String(count);

//遍历

for (int i=0;inum.count;i++)

{

//这里面完成累加就可以了。

}

}

}

我只能给你这么多了,再给你答案就是害你了。努力吧

Java大一的题目求大神帮忙看看怎么写TAT求源代码

哈哈~网上很多哈,GUI我也不会,现学现卖一个

package swing;

import javafx.embed.swing.JFXPanel;

import javax.swing.*;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.text.DateFormat;

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Date;

/**

* @author wenxy

* @create 2020-05-01

*/

public class JavaFxDate {

public static void main(String[] args) {

// 创建 JFrame 实例

JFrame frame = new JFrame();

// Setting the width and height of frame

frame.setSize(310, 180);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

/* 创建面板,这个类似于 HTML 的 div 标签

* 我们可以创建多个面板并在 JFrame 中指定位置

* 面板中我们可以添加文本字段,按钮及其他组件。

*/

JPanel panel = new JPanel();

// 添加面板

frame.add(panel);

/*

* 调用用户定义的方法并添加组件到面板

*/

placeComponents(panel);

// 设置界面可见

frame.setVisible(true);

}

private static void placeComponents(JPanel panel) {

/* 布局部分我们这边不多做介绍

* 这边设置布局为 null

*/

panel.setLayout(null);

// 创建 JLabel

JLabel userLabel = new JLabel("请输入日期字符串");

userLabel.setBounds(5, 5, 300, 25);

panel.add(userLabel);

/*

* 创建文本域用于用户输入

*/

JTextField userText = new JTextField(20);

userText.setBounds(5, 40, 200, 25);

panel.add(userText);

// 创建 JLabel

JLabel showLable = new JLabel();

showLable.setBounds(5, 70, 300, 25);

panel.add(showLable);

// 创建登录按钮

JButton loginButton = new JButton("转换");

loginButton.setBounds(180, 40, 100, 25);

loginButton.addActionListener(new ActionListener() {

DateFormat input = new SimpleDateFormat("yyyy-MM-dd");

DateFormat output = new SimpleDateFormat("yyyy年MM月dd日");

{

input.setLenient(false);    // 设置严格按格式匹配

output.setLenient(false);

}

@Override

public void actionPerformed(ActionEvent actionEvent) {

try {

Date date = convert(userText.getText());

showLable.setText("成功:" + output.format(date));

showLable.setForeground(Color.GREEN);

} catch (WrongDateException e) {

showLable.setText(e.getMessage());

showLable.setForeground(Color.RED);

}

}

private Date convert(String text) throws WrongDateException {

try {

return input.parse(text);

} catch (ParseException e) {

throw new WrongDateException(text);

}

}

});

panel.add(loginButton);

}

static class WrongDateException extends Exception {

WrongDateException(String s) {

super(s + "不是合法的日期字符串");

}

}

}

「大一java考试编程题」Java编程试题

大一Java作业题

首先回答您的do-while的问题,while中是条件为true的时候继续执行do里面的代码,当为false的时候结束执行。下面是您的问题的一种解决办法,忘采纳。

import java.util.Scanner;

public class JuiceVendingCashFlow {

public static int total = 0;

public static int customernum =0;

public static double income = 0;

public double income (double w,double t){

income += (w/100)*3.5+t*1.5;

total++;

customernum++;

return income;

}

public static void main(String[] args) throws Exception {

JuiceVendingCashFlow f= new JuiceVendingCashFlow();

double weight = 0;

System.out.println("Customer"+"#"+ ++customernum+" welcome!");

do {

System.out.print("how much juice are you after?");

try{

Scanner s = new Scanner(System.in);

weight = s.nextDouble();

if(weight0) {

throw new Exception();

}

} catch (Exception e) {

System.out.println("OVER");

}

if (weight=0) {

System.out.println("how many toppings would you like?");

Scanner b = new Scanner(System.in);

double topping = b.nextDouble();

f.income(weight, topping);

}

} while (weight=0);

System.out.println(income+" "+ --customernum);

}

}

此方法写的仓促其中如果topping为负值的时候会出现异常,您可以写一个异常抛出来解决问题。

大一JAVA题。求解

第1个文件:Person.java

public class Person{

private String name;

private String sex;

private String age;

private String country;

public void eat(){

System.out.println("Person吃饭");

}

public void sleep(){

System.out.println("Person睡觉");

}

public void work(){

System.out.println("Person工作");

}

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 String getAge() {

return age;

}

public void setAge(String age) {

this.age = age;

}

public String getCountry() {

return country;

}

public void setCountry(String country) {

this.country = country;

}

}

第2个文件:Student.java

public class Student extends Person{

private String school;

private String number;

public void work(){

System.out.println("学生在认真学习");

}

public static void main(String[] args){

Student s = new Student();

s.setName("张无忌 ");

s.setSex("男 ");

s.setAge("22 ");

s.setCountry("元朝 ");

s.school="明教 ";

s.number="1 ";

s.work();

s.sleep();

s.eat();

System.out.println(s.getName() + s.getSex() + s.getAge() + s.getCountry() + s.school + s.number);

}

public String getSchool() {

return school;

}

public void setSchool(String school) {

this.school = school;

}

public String getNumber() {

return number;

}

public void setNumber(String number) {

this.number = number;

}

}

第3个文件:Worker.java

public class Worker extends Person{

private String unit;

private String working_age;

public void work(){

System.out.println("工人努力工作赚钱");

}

public static void main(String[] args){

Worker w = new Worker();

w.setName("赵敏 ");

w.setSex("女 ");

w.setAge("20 ");

w.setCountry("元朝 ");

w.unit="绍敏郡主 ";

w.working_age="3 ";

w.work();

w.sleep();

w.eat();

System.out.println(w.getName() + w.getSex() + w.getAge() + w.getCountry() + w.unit + w.working_age);

}

public String getUnit() {

return unit;

}

public void setUnit(String unit) {

this.unit = unit;

}

public String getWorking_age() {

return working_age;

}

public void setWorking_age(String working_age) {

this.working_age = working_age;

}

}

第4个文件:Cadre.java

public class Cadre extends Student{

private String position;

public void meeting(){

System.out.println("学生干部在开会");

}

public static void main(String[] args){

Cadre c = new Cadre();

c.setName("周芷若 ");

c.setSex("女 ");

c.setAge("23 ");

c.setCountry("元朝 ");

c.setSchool("峨眉 ");

c.setNumber("3 ");

c.position="峨眉派掌门 ";

c.meeting();

c.work();

c.sleep();

c.eat();

System.out.println(c.getName() + c.getSex() + c.getAge() + c.getCountry() + c.getSchool() + c.getNumber() + c.position);

}

public String getPosition() {

return position;

}

public void setPosition(String position) {

this.position = position;

}

}

大一编程入门java,这道题怎么做呢?

========汽车Auto类========================

package com.cn.answer;

/**

* 这是汽车类 Auto

* @Title: Auto.java

* @Description:

* @author

* @date 2020-06-10 09:51:08

*/

public class Auto {

public double speed;

public void start(){

System.out.println("这是启动的方法start");

}

public void speedUp(){

System.out.println("这是加速的方法speedUp");

}

public void stop(){

System.out.println("这是停止的方法stop");

}

public double getSpeed() {

return speed;

}

public void setSpeed(double speed) {

this.speed = speed;

}

@Override

public String toString() {

return "Auto [speed=" + speed + "]";

}

}

===========================================

=============这是Auto的子类Bus类===========

package com.cn.answer;

/**

* 这是Auto的子类Bus类

* @Title: Bus.java

* @Description:

* @author 二娃子

* @date 2020-06-10 09:55:01

*/

public class Bus extends Auto {

private int passenger;

public Bus(int passenger) {

super();

this.passenger = passenger;

}

public int getPassenger() {

return passenger;

}

public void setPassenger(int passenger) {

this.passenger = passenger;

}

/**

* 这是乘客上车的方法

* @param passenterNum 乘客上车的人数

* @return

*/

public int gotOn(int passenterNum){

this.passenger+=passenterNum;

return passenger;

}

/**

* 这是乘客下车的方法

* @param passenterNum 乘客下车的人数

* @return

*/

public int gotOff(int passenterNum){

this.passenger-=passenterNum;

return passenger;

}

}

=============这是Auto的子类Bus类 结束===========

==========测试类=====================

/**

* 这是Bus的测试类

* @Title: BusTest.java

* @Description:

* @author 二娃子

* @date 2020-06-10 09:58:08

*/

public class BusTest {

public static void main(String[] args) {

//创建Bus类,设置一个初始化的乘客人数(这里比如是10人)

Bus bus = new Bus(10);

//测试上车的人数

int passenger = bus.gotOn(5);

//输出现在车上的人数

System.out.println(passenger);

//测试下车的人数

int passenger2 = bus.gotOff(10);

//输出现在车上的人数

System.out.println(passenger2);

}

}

==============测试类结束==========

大一java考试编程题的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于Java编程试题、大一java考试编程题的信息别忘了在本站进行查找喔。

The End

发布于:2022-11-21,除非注明,否则均为首码项目网原创文章,转载请注明出处。