Java编程的请进来看看....

来源:百度知道 编辑:UC知道 时间:2024/05/17 13:37:32
编写一个程序,用以判断一个五位整数n的奇偶性,并求出它们的和.
比如(n=12345) 运行的结果为 偶数个数:2 奇数个数:3
这东西想了好久,可一点办法都没有!在这先谢谢各位了!

package test;
import java.io.*;
public class test
{
public static final int MAX_BUF = 1024;
public static void main(String[] args)
{

System.out.println("请你输入一个五位数:");
try
{

java.io.BufferedInputStream readbuf = new BufferedInputStream(System.in);
byte[] bytearray = new byte[5];
readbuf.read(bytearray);
String strValue = new String(bytearray);
int ia = 0,ib = 0;
/* for(int i = 0;i < strValue.length();i ++)
{
System.out.println(strValue.substring(i,i + 1));
}*/
for(int i = 0;i < strValue.length(); i ++)
{
if(Integer.parseInt(strValue.substring(i,i + 1)) % 2 ==0 )
{
ia ++;