给你一个前几天才帮人写的
创新互联建站,为您提供成都网站建设、成都网站制作、网站营销推广、网站开发设计,对服务成都咖啡厅设计等多个行业拥有丰富的网站建设及推广经验。创新互联建站网站建设公司成立于2013年,提供专业网站制作报价服务,我们深知市场的竞争激烈,认真对待每位客户,为客户提供赏心悦目的作品。 与客户共同发展进步,是我们永远的责任!
“计算整钱兑零”。程序要求用户输入一个双精度数代表总元数,就会列出总值与其等价的1元币、二角五分币、5分币和1分币的数目。程序报告的数目是1元币的最大数、其次是二角五分币的最大数,等等,依此类推。只显示非零的单位。对单个单位显示单数单词,对多于一个单位的显示复数单词
import java.util.Scanner;
public class MoneyCalculate {
public static void main(String[] args) {
int max100 = 0;
int max25 = 0;
int max5 = 0;
int max1 = 0;
double money = getMoneyFromInput();
String str = String.valueOf(money).trim();
String[] ary = str.split("\\.");
max100 = Integer.parseInt(ary[0]);
if(ary.length == 2){
int fen = Integer.parseInt(ary[1]);
if(ary[1].trim().length() == 1){
fen = Integer.parseInt(ary[1]) * 10;
}
max25 = fen / 25;
if(fen % 25 != 0){
fen = fen % 25;
}else{
fen = 0;
}
max5 = fen / 5;
max1 = fen % 5;
}
StringBuilder sb = new StringBuilder(money + " = ");
if(max100 != 0){
sb.append(max100);
sb.append("*1 ");
}
if(max25 != 0){
sb.append(max25);
sb.append("*0.25 ");
}
if(max5 != 0){
sb.append(max5);
sb.append("*0.05 ");
}
if(max1 != 0){
sb.append(max1);
sb.append("*0.01 ");
}
System.out.println(sb.toString());
}
private static double getMoneyFromInput() {
Scanner scanner = new Scanner(System.in);
return scanner.nextDouble();
}
}
-----------
2.49
2.49 = 2*1 1*0.25 4*0.05 4*0.01
-----------
2.5
2.5 = 2*1 2*0.25
-----------
37.23
37.23 = 37*1 4*0.05 3*0.01
-----------------
123.569
123.569 = 123*1 22*0.25 3*0.05 4*0.01
package test;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Test5 extends Applet {
private final Panel pan = new Panel();
private final Label time = new Label();
private final Button btnGo = new Button("开始");
private final Button btnPouse = new Button("暂停");
private final Button btnReset = new Button("复位");
private final StopwatchThread swThread = new StopwatchThread();
private class btnGoListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
swThread.go();
btnGo.setEnabled(false);
}
}
private class btnPouseListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
if(btnGo.isEnabled()){
return ;
}
if (btnPouse.getLabel().equals("继续")) {
swThread.go();
btnPouse.setLabel("暂停");
} else if (btnPouse.getLabel().equals("暂停")) {
swThread.noGo();
btnPouse.setLabel("继续");
}
}
}
private class btnResetListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
swThread.reset();
btnGo.setEnabled(true);
btnGo.setLabel("开始");
btnPouse.setLabel("暂停");
}
}
private class StopwatchThread extends Thread {
private boolean going = false;
private long prevElapsed = 0;
private Date startDate = new Date();
private long elapsedTime() {
return prevElapsed +
(going ? new Date().getTime() - startDate.getTime() : 0);
}
private String msToString(long time) {
System.out.println(time+" "+((0*60+2)*1000+999));
if(((99*60+59)*1000+983)=time((99*60+59)*1000+999)=time){//((0*60+2)*1000+983)=time((0*60+2)*1000+999)=time
if (time % 1000 990)
time += 2;
swThread.noGo();
}
String ms, sec, min;
if (time % 10 = 5)
time += 5;
ms = Long.toString(time % 1000);
while (ms.length() 3)
ms = "0" + ms;
ms = ms.substring(0, ms.length() - 1);
time /= 1000;
sec = Long.toString(time % 60);
if (sec.length() == 1) sec = "0" + sec;
time /= 60;
min = Long.toString(time);
return min + ":" + sec + "." + ms;
}
public void go() {
startDate = new Date();
going = true;
}
public void noGo() {
prevElapsed = elapsedTime();
going = false;
}
public void reset() {
going = false;
prevElapsed = 0;
}
public void run() {
while (true) {
time.setText(msToString(elapsedTime()));
yield();
}
}
}
public void init() {
setLayout(new GridLayout(2,2));
setBackground(Color.lightGray);
setForeground(Color.black);
pan.setLayout(new GridLayout(3,2));
pan.add(new Label("计时:"));
time.setForeground(Color.blue);
pan.add(time);
pan.add(btnGo);
pan.add(btnPouse);
pan.add(btnReset);
pan.add(new Label());
add(pan);
btnGo.addActionListener(new btnGoListener());
btnReset.addActionListener(new btnResetListener());
btnPouse.addActionListener(new btnPouseListener());
swThread.setDaemon(true);
swThread.start();
}
public static void main(String[] args) {
Test5 applet = new Test5();
Frame aFrame = new Frame("计时器");
aFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
aFrame.add(applet, BorderLayout.CENTER);
aFrame.setSize(400, 200);
applet.init();
applet.start();
aFrame.setVisible(true);
}
}
可以改变有注释的那个if语句里面的值来判断什么时候停止
Java代码:
import java.io.File;
import java.io.IOException;
public class Test10 {
public static void main(String[] args) {
//创建“abc”文件夹
String pathName = "d:\\abc";
File path = new File(pathName);
path.mkdir();
//创建“abc”文件
String fileName = "d:\\abc\\abc";
File file = new File(fileName);
try {
file.createNewFile();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
下面是一个简单的 Java 程序示例,用于实现山羊和狼的继承关系,并在测试类中进行验证:
Animal.java:
```java
public abstract class Animal {
public void walk() {
System.out.println("走路");
}
public abstract void eat();
}
```
Goat.java:
```java
public class Goat extends Animal {
@Override
public void eat() {
System.out.println("吃草");
}
}
```
Wolf.java:
```java
public class Wolf extends Animal {
@Override
public void eat() {
System.out.println("吃肉");
}
}
```
AnimalTest.java:
```java
public class AnimalTest {
public static void main(String[] args) {
Goat goat = new Goat();
wolf wolf = new wolf();
goat.eat(); // 输出:吃草
wolf.eat(); // 输出:吃肉
goat.walk(); // 输出:走路
wolf.walk(); // 输出:走路
}
}
```
在此程序中,我们定义了一个 `Animal` 类作为基类,包含了所有动物都会有的行为(例如走路),并使用抽象方法 `eat()` 表示不同动物的饮食习惯。然后通过继承实现 `Goat` 和 `Wolf` 两个子类,并分别重写 `eat()` 方法。
在测试类中,我们分别创建了一个 `Goat` 和一个 `Wolf` 对象,并分别调用其 `eat()` 和 `walk()` 方法进行验证。可以看到,不同的动物具备不同的饮食习惯,但它们的走路行为是一致的。