public class Coin {
private int head = 1
private int tail = 0
private int result
public int getResult() {
return result
}
public void setResult(int result) {
this.result = result
}
public Coin(){
result = 1
}
public void throwCoin(){
int random = (int) (Math.random() * 10 / 5)
if(head == random){
result = head
}else{
result = tail
}
}
public int getHead() {
return head
}
public void setHead(int head) {
this.head = head
}
public int getTail() {
return tail
}
public void setTail(int tail) {
this.tail = tail
}
}
// 测试类
public class Test {
public static void main(String[] args) {
Coin coin = new Coin()
coin.throwCoin()
if(coin.getResult() == coin.getHead()){
System.out.println("You Win.")
}else if(coin.getResult() == coin.getTail()){
System.out.println("You Lose.")
}
}
}
public class Throwcoin {/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成的方法存根
for (int i = 1i <= 20i++) {
int j = (int) (Math.random() * 2)
if (j == 0) {
System.out.println("数凯第"+i+"次抛硬币:硬币正面拦型朝上")
} else {
System.out.println("第"简毕猜+i+"次抛硬币:硬币反面朝上")
}
}
}
}
import java.util.Scannerpublic class 美元
{
private static 唯老唯Scanner sc=new Scanner(System.in)
public static void main(String[] args)
{
System.out.println("\n\t\t==========提示:1美指培元=100美分=========\n")
System.out.println("请输入钱数美元为单位,自动转换成美分!")
while(true)
init(sc.nextInt())
}//初始化!
private static void init(int n)
{
int x=n*100,i=0
for (int a=1a<x a+=25 )
{
for (int b=1b<x b+=10 )
{
for (int c=1 c<xc+=5 )
{
for (int d=1d<x 含烂d++ )
{
if((a*25+b*10+c*5+d)==x)
{
i++
System.out.print("25美分==>"+a+"\t10美分==>"+b+"\t5美分==>"+c+"\t1美分==>"+d+"\n")
}
}
}
}
}
System.out.println("\n你输入的是:"+n+"美元==>"+x+"美分\t一共可以有"+i+"种可能!\n\n继续测试:")
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)