//我记得我昨天刚刚回答了一个一摸一样的问题。。
/咐裤/先写第一个程序
import java.util.Scanner;
public class Program1 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("请输入一个整数:");
int i = in.nextInt();
char[] c = String.valueOf(i).toCharArray();
String s1 = "13579";
String s2 = "24680"伏亮;
int num1 = 0;
int num2 = 0;
for (int j = 0; j < c.length; j++) {
if (s1.contains(String.valueOf(c[j]))) {
num1++;
}
if (s2.contains(String.valueOf(c[j]))) {
num2++;
}
}
System.out.println("偶数个数:"+num2);
System.out.println("奇数个数:"+num1);
}
}
//第衡厅简二个程序
import java.util.Scanner;
public class Program2 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("请输入顾客支付金额");
int ipay = in.nextInt();
System.out.println("请输入顾客消费金额");
int icast = in.nextInt();
if (ipay < icast) {
System.out.println("顾客支付不足,还应支付" + (icast - ipay));
}
if (ipay == icast) {
System.out.println("顾客支付等于消费金额,无需找零");
}
if (ipay > icast) {
System.out.println("顾客支付大于消费金额,应找零钱" + (ipay - icast));
System.out.println("<余额细目>");
int i = ipay - icast;
i = paint(i, 5000);
i = paint(i, 1000);
i = paint(i, 500);
i = paint(i, 100);
i = paint(i, 50);
i = paint(i, 10);
i = paint(i, 5);
i = paint(i, 1);
}
}
private static int paint(int i, int money) {
int num = 0;
while (i > money) {
i -= money;
num++;
}
System.out.println(money + "元:" + num + "张");
return i;
}
}
一、public class oddnum {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int num = 123226677;
int odd = 0;
int length = 0;
while(num != 0){
odd += num % 2;
length++;
num = num /10;
}
System.out.println("奇数位个数是"+odd+"个;偶数位个数是"+(length - odd)+"个";);
}
}
奇数位个数是4个;偶数位个数是5个;你可以照着这个算法实现。
先给你一个,明天给你第二个。要睡觉段蚂了
第二个
import java.util.Scanner;
public class Program2 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("请输入顾客支付金额"判缓);
int ipay = in.nextInt();
System.out.println("请输入顾客消费金额");
int icast = in.nextInt();
if (ipay < icast) {
System.out.println("顾客支付不足,还应支付" + (icast - ipay));
}
if (ipay == icast) {
System.out.println("顾握冲埋客支付等于消费金额,无需找零");
}
if (ipay > icast) {
System.out.println("顾客支付大于消费金额,应找零钱" + (ipay - icast));
System.out.println("<余额细目>");
int i = ipay - icast;
i = paint(i, 5000);
i = paint(i, 1000);
i = paint(i, 500);
i = paint(i, 100);
i = paint(i, 50);
i = paint(i, 10);
i = paint(i, 5);
i = paint(i, 1);
}
}
private static int paint(int i, int money) {
int num = 0;
while (i > money) {
i -= money;
num++;
}
System.out.println(money + "元:" + num + "张");
return i;
}
}