「java源码题」JAVA编程题库

博主:adminadmin 2022-12-29 08:54:08 66

今天给各位分享java源码题的知识,其中也会对JAVA编程题库进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

求解两道java题目,请发送源代码!

第二题的

import java.io.File;

public class FileList {

public static void printContentInOneDirectory(File path, int depth) {

for(int i = 0; i  depth; i++)

System.out.print("--");

if(path.isDirectory())

System.out.print("[目录] ");

else

System.out.print("[文件] ");

System.out.println(path.getName());

}

public static void readFileAndDirectory(File path, int depth) {

if(path.exists()) {

printContentInOneDirectory(path, depth);

if(path.isDirectory()) {

File[] files = path.listFiles();

for(File file : files)

readFileAndDirectory(file, depth + 1);

}

}

}

public static void main(String[] args) {

FileList.readFileAndDirectory(new File("D:/GIF Movie Gear"), 0);

}

}

java问题 求个源码(求大手子们帮帮)

public static void main(String[] args) {

System.out.println("请输入长:");

Scanner sc = new Scanner(System.in);

int c = sc.nextInt();

System.out.println("请输入宽:");

int k = sc.nextInt();

System.out.println("矩形如下:");

for (int i = 0; i k; i++) {

for (int j = 0; j c; j++) {

System.out.print("* ");

}

System.out.println();

}

}

运行结果

刚刚长宽弄错了,修改了一下,望采纳,谢谢。

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编程题 求源代码

public class Invoice {

String bianhao = null;

String shuoming = null;

int count = 0;

double price = 0.0;

public Invoice(String bianhao, String shuoming, int count, double price) {

this.bianhao = bianhao;

this.shuoming = shuoming;

if (count 0) {

this.count = 0;

} else {

this.count = count;

}

if (price 0.0) {

this.price = 0.0;

} else {

this.price = price;

}

}

public double getInvoiceAmount() {

return count * price;

}

public String getBianhao() {

return bianhao;

}

public void setBianhao(String bianhao) {

this.bianhao = bianhao;

}

public int getCount() {

return count;

}

public void setCount(int count) {

this.count = count;

}

public double getPrice() {

return price;

}

public void setPrice(double price) {

this.price = price;

}

public String getShuoming() {

return shuoming;

}

public void setShuoming(String shuoming) {

this.shuoming = shuoming;

}

}

public class InvoiceTest {

/**

* @param args

*/

public static void main(String[] args) {

Invoice invoice = new Invoice("010220", "Desk", 50, 53.9);

System.out.println(invoice.getInvoiceAmount());

}

}

求解一个Java题目,给出参考源码。谢谢

public class PriceDemo {

public static void main(String[] args) {

String str = "北京烤鸭:189 西芹百合:15 清蒸鲈鱼:80";

String[] foods = str.split(" ");//拆分字符串 每个字符串保留一道菜的信息

double total = 0;

for (int i = 0; i  foods.length; i++) {

String[] food =foods[i].split(":");//拆分字符串 分出菜名和单价

System.out.println("菜品:"+food[0]+"\t单价:"+food[1]);

total = total+Double.parseDouble(food[1]);

}

System.out.println("以上菜品总价为:"+total);

}

}

输出

菜品:北京烤鸭 单价:189

菜品:西芹百合 单价:15

菜品:清蒸鲈鱼 单价:80

以上菜品总价为:284.0

Java题,求大佬给个源码

public class Student {

String id;

String gender;

String name;

int age;

public String say() {

return id+gender+name+age;

}

public void sayHi() {

System.out.println("大家好,我叫" + name + ",学号" + id + ",性别" + gender + ",今年" + age + ",很高兴权认识大家!");

}

}

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

The End

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