你的第一题看不懂
什么是
由程序中声明差赋值三个整数的初值?
package tw.com.foxcavity.ks.wangjun.baidu;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import tw.com.foxcavity.ks.wangjun.baidu.exception.InValideParametersException;
public class test {
private int[] zhaoling;
public test() {
zhaoling = new int[6];
zhaoling[0] = 0;//500
zhaoling[1] = 0;//100
zhaoling[2] = 0;//50
zhaoling[3] = 0;//10
zhaoling[4] = 0;//5
zhaoling[5] = 0;//1
}
/**
* 检查输入的参数是否符合格式
* @param str
* @return
* @throws InValideParametersException
*/
public String[] checkPara(String str) throws InValideParametersException {
String[] paras = str.split(";");
if(paras.length == 0)
throw new InValideParametersException("请输入正确的参数!\n " +
"userage:<所应付款的金额>;<实际交给店员的金额>");
return paras;
}
/**
* 获得的输入参数
* @return
* @throws IOException
* @throws InValideParametersException
*/
public String getSystemIn() throws IOException,InValideParametersException {
System.out.println("请输入参数:");
BufferedReader br;
String str = "";
try {
br = new BufferedReader(new InputStreamReader(System.in));
if (br == null) {
throw new InValideParametersException("请输入参数!\n " +
"userage:<所应付款的金额>;<实际交给店员的金额>");
}
str = br.readLine();
}catch (IOException ex) {
ex.printStackTrace();
}
return str;
}
/**
* 计算零钱格式
* @param str
*/
public int cal(int money) {
int div = 0;
int mod = 0;
if(money > 500){
div = money / 500;
mod = money % 500;
zhaoling[0] = div;
}else if(money > 100){
div = money / 100;
mod = money % 100;
zhaoling[1] = div;
}else if(money > 50){
div = money / 50;
mod = money % 50;
zhaoling[2] = div;
}else if(money > 10){
div = money / 10;
mod = money % 10;
zhaoling[3] = div;
}else if(money > 5){
div = money / 5;
mod = money % 5;
zhaoling[4] = div;
}else{
div = money / 1;
mod = money % 1;
zhaoling[5] = div;
}
return mod;
}
public String showMoney() {
String str = String.valueOf(zhaoling[0]) + String.valueOf(zhaoling[1]) + String.valueOf(zhaoling[2]) +
String.valueOf(zhaoling[3]) + String.valueOf(zhaoling[4]) + String.valueOf(zhaoling[5]);
return str;
}
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) {
test t = new test();
try{
String str = t.getSystemIn();
String[] paras = t.checkPara(str);
int a = Integer.parseInt(paras[0]);//所应付款的金额
int b = Integer.parseInt(paras[1]);//实际交给店员的金额
int c = b - a;//零钱
while(c > 0){
c = t.cal(c);
}
System.out.println(t.showMoney());
}catch(IOException e){
System.out.println(e.getMessage());
}catch(InValideParametersException ie){
System.out.println(ie.getMessage());
}
}
}
package tw.com.foxcavity.ks.wangjun.baidu.exception;
public class InValideParametersException extends Exception {
public InValideParametersException(String msg) {
super(msg);
}
}
是呀, 第一道题,是什么意思呀
由程序中声明差赋值三个整数的初值
能给我一个解释吗???
第一道题:
/*
* Created on 2005-11-13
*/
package test;
/**
* @author handpower
*/
public class Test {
public static void main(String[] args) {
//取三个1-100的随机整数
int i1 = (int) Math.floor(1 + Math.random() * 100);
int i2 = (int) Math.floor(1 + Math.random() * 100);
int i3 = (int) Math.floor(1 + Math.random() * 100);
//显示一下
System.out.println(i1 + " " + i2 + " " + i3);
int max = i1;
int min = i2;
if (max < min) {
max = i2;
min = i1;
}
if (max < i3) {
max = i3;
} else if (min > i3) {
min = i3;
}
//输出最大最小值
System.out.println("the max number is " + max);
System.out.println("the min number is " + min);
//输出平均数
System.out.println("the average value is " + (double)(i1 + i2 + i3)/3);
}
}
如果晓得,,告诉我看,我对这个感兴趣!
zzfengjian@126.com
收藏
see