一个三位数字(如:102),
------------
封装成一个类
class MyClass {
int first;
int second;
in third;
}
------------
封装成一个类
class MyClass {
int first;
int second;
in third;
}
解决方案 »
- JAVA关于一个Hibernate实体类分组统计的问题
- Spring 事务回滚问题 声明式事务回滚失败
- java连接mysql问题
- CSS嵌套层布局
- 如何实现任意对象转换为XML格式
- hibernate 对付 miscrosoft access 出现的问题 ,我相信大家一定遇到过
- 用resin能不能使用EJB?
- WSAD内JDBC连接
- 我想用一个WebService传送XML格式的ResultSet,但是该怎么写这个Service的方法呢?
- 关于Tomcat修改端口号的问题
- 一个Graphics 画图的小问题
- Connection reset by peer: socket write error 高手出招(偶等待之中)
可以考虑考虑
public class BitOperator
{
private String _strValue = "";
public String getValue()
{
return _strValue;
}
public void setValue(String strValue)
{
_strValue = strValue;
} public String getResult()
{
String strResult = "";
for (int i = 0; i < _strValue.length(); i++)
{
char ch = _strValue.charAt(i);
if (ch < '0' || ch > '2')
{
strResult += "未知";
continue;
}
switch(ch & 3)
{
case 0 : strResult += "红"; break;
case 1 : strResult += "黄"; break;
case 2 : strResult += "绿"; break;
case 3 : strResult += "未知"; break;
default : strResult += "未知";
} }
return strResult;
} public static void main(String [] args)
{
BitOperator test = new BitOperator();
test.setValue("0ab$%&99211");
System.out.println(test.getResult()); }
}
public class Test
{
public static void main(String[] args)
{
String s=args[0];
int r=0,y=0,g=0;
for(int i=0;i<s.length();i++)
{
switch(s.charAt(i))
{
case '0':r++;break;
case '1':y++;break;
case '2':g++;break;
}
}
System.out.println(r+"红"+y+"黄"+g+"绿");
}
}
不过,只有 haroyy(天平) 的思路是符合我的要求的,非常感谢您!