艹,晚了几分钟:
import java.util.ArrayList;
import java.util.List;
public class Counter {
int x;//No of 1yuan
int y;//No if 5jiao
int z;//No of 1jiao
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public int getZ() {
return z;
}
public void setZ(int z) {
this.z = z;
}
public static void main(String[] args) {
ListresultList = new ArrayList ();
for(int j = 1;j<100;j++)
{
for(int k = 1;k<100;k++)
{
for(int m = 1;m<100;m++)
{
if(j*1 + k*0.5 + m*0.1 == 100 && j <= ( k+m ))
{
Counter obj = new Counter();
obj.setX(j);
obj.setY(k);
obj.setZ(m);
resultList.add(obj);
}
}
}
}
System.out.println("总共有"+resultList.size()+"种组合满足要求,其中一元硬币数目最多的组合是:\r\n"+
"一元硬币"+Counter.getMaxYiYuanCounter(resultList).getX()+"个\r\n");
}
public static Counter getMaxYiYuanCounter(ListresultList){
int maxCounter=0;
for(int i = 0;i < resultList.size();i++)
{
if(maxCounter < resultList.get(i).getX())
maxCounter = resultList.get(i).getX();
else;
}
for(int i = 0;i < resultList.size();i++)
{
if(maxCounter == resultList.get(i).getX())
return resultList.get(i);
}
return null;
}
}
package zhidao;
public class Cleaner
{
private static int guess ()
{
int max = Integer.MIN_VALUE;
for ( int i = 0; i < 100 / 0.1; i++ )
{
for ( int j = 0; j < 100 / 0.5; j++ )
{
for ( int k = 0; k < 100; k++ )
{
if (i * 0.1 + j * 0.5 + k * 1 == 100 && i + j >= k)
{
System.out.println ("1角: " + i + " , 5角: " + j + " , 1元: " + k);
max = max < k ? k : max;
}
}
}
}
return max;
}
public static void main ( String[] args )
{
System.out.println ("1元最多有:" + guess ());
}
}