java编程求帮忙修改
publicclasspoke{publicstaticvoidmain(String[]args)throwsIOException{poke2poke2=newpok...
public class poke {
public static void main(String[] args) throws IOException {
poke2 poke2 = new poke2();
poke2.getResult();
}
}
class poke2{
public void getResult() throws IOException {
final int NUMBER_OF_CARDS = 52;
int number = (int)(Math.random() * NUMBER_OF_CARDS);
System.out.print("The card you picked is ");
if (number % 13 == 0)
System.out.print("Ace of ");
else if (number % 13 == 10)
System.out.print("Jack of ");
else if (number % 13 == 11)
System.out.print("Queen of ");
else if (number % 13 == 12)
System.out.print("King of ");
else
System.out.print((number % 13) + " of ");
if (number / 13 == 0)
System.out.println("Clubs");
else if (number / 13 == 1)
System.out.println("Diamonds");
else if (number / 13 == 2)
System.out.println("Hearts");
else if (number / 13 == 3)
System.out.println("Spades");
System.out.println("您是否要继续?");
InputStream inputStream = System.in;
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
if('y' == ((char)inputStreamReader.read())) {
this.getResult();
}
else {
System.out.println("程序结束");
}
}
}
我想要做的程序是从52张扑克牌(不包括大小王)随机抽一张出来然后会询问是否继续然后继续或者结束程序,有大神能帮帮忙修改下吗? 展开
public static void main(String[] args) throws IOException {
poke2 poke2 = new poke2();
poke2.getResult();
}
}
class poke2{
public void getResult() throws IOException {
final int NUMBER_OF_CARDS = 52;
int number = (int)(Math.random() * NUMBER_OF_CARDS);
System.out.print("The card you picked is ");
if (number % 13 == 0)
System.out.print("Ace of ");
else if (number % 13 == 10)
System.out.print("Jack of ");
else if (number % 13 == 11)
System.out.print("Queen of ");
else if (number % 13 == 12)
System.out.print("King of ");
else
System.out.print((number % 13) + " of ");
if (number / 13 == 0)
System.out.println("Clubs");
else if (number / 13 == 1)
System.out.println("Diamonds");
else if (number / 13 == 2)
System.out.println("Hearts");
else if (number / 13 == 3)
System.out.println("Spades");
System.out.println("您是否要继续?");
InputStream inputStream = System.in;
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
if('y' == ((char)inputStreamReader.read())) {
this.getResult();
}
else {
System.out.println("程序结束");
}
}
}
我想要做的程序是从52张扑克牌(不包括大小王)随机抽一张出来然后会询问是否继续然后继续或者结束程序,有大神能帮帮忙修改下吗? 展开
3个回答
展开全部
import java.util.Scanner;
public class GetCard {
final static String[] suits = { "Heart ", "Spade ", "Diamond ", "Club " }; // 扑克花色
final static String[] cards = { "A", "2", "3", "4", "5", "6", "7", "8",
"9", "10", "J", "Q", "K" }; //扑克牌面大小
final static int suit_num = 4;//扑克一共4种花色
final static int card_num = 13;//扑克一共13种牌值
public static void getCard(){
int suit_index = (int)(Math.random()*suit_num);
int card_index = (int)(Math.random()*card_num);
String card = suits[suit_index] + " of " + cards[card_index];
System.out.println(card);
}
public static void main(String[] args) {
getCard();
while(true){
System.out.print("您是否要继续?(Y/N)");
Scanner scan = new Scanner(System.in);
String s = scan.nextLine();
if("n".equalsIgnoreCase(s)){
break;
} else if("y".equalsIgnoreCase(s)){
getCard();
}else{
System.out.println("输入错误,请重新输入!!");
}
}
System.out.println("程序结束!!");
}
}
我觉得你这样写太麻烦了,你看看这一段程序,希望对你有帮助,如有疑问可以追问
祝学习顺利。
public class GetCard {
final static String[] suits = { "Heart ", "Spade ", "Diamond ", "Club " }; // 扑克花色
final static String[] cards = { "A", "2", "3", "4", "5", "6", "7", "8",
"9", "10", "J", "Q", "K" }; //扑克牌面大小
final static int suit_num = 4;//扑克一共4种花色
final static int card_num = 13;//扑克一共13种牌值
public static void getCard(){
int suit_index = (int)(Math.random()*suit_num);
int card_index = (int)(Math.random()*card_num);
String card = suits[suit_index] + " of " + cards[card_index];
System.out.println(card);
}
public static void main(String[] args) {
getCard();
while(true){
System.out.print("您是否要继续?(Y/N)");
Scanner scan = new Scanner(System.in);
String s = scan.nextLine();
if("n".equalsIgnoreCase(s)){
break;
} else if("y".equalsIgnoreCase(s)){
getCard();
}else{
System.out.println("输入错误,请重新输入!!");
}
}
System.out.println("程序结束!!");
}
}
我觉得你这样写太麻烦了,你看看这一段程序,希望对你有帮助,如有疑问可以追问
祝学习顺利。
展开全部
import java.io.IOException;
import java.util.Scanner;
/**
* @author Administrator
*
*/
public class Poke {
public static void main(String[] args) throws IOException {
poke2 poke2;
poke2= new poke2();
poke2.getResult();
while(true){
System.out.println("请选择操作:\n1.继续选牌\n2.结束程序");
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
switch(a){
case 1:
poke2 = new poke2();
poke2.getResult();
break;
case 2:
System.out.print("程序已经结束!");
System.exit(0);
default :
System.exit(0);
}
}
}
}
class poke2{
public void getResult() throws IOException {
final int NUMBER_OF_CARDS = 52;
int number = (int)(Math.random() * NUMBER_OF_CARDS);
System.out.print("The card you picked is ");
if (number % 13 == 0)
System.out.print("Ace of ");
else if (number % 13 == 10)
System.out.print("Jack of ");
else if (number % 13 == 11)
System.out.print("Queen of ");
else if (number % 13 == 12)
System.out.print("King of ");
else
System.out.print((number % 13) + " of ");
if (number / 13 == 0)
System.out.println("Clubs");
else if (number / 13 == 1)
System.out.println("Diamonds");
else if (number / 13 == 2)
System.out.println("Hearts");
else if (number / 13 == 3)
System.out.println("Spades");
}
}
import java.util.Scanner;
/**
* @author Administrator
*
*/
public class Poke {
public static void main(String[] args) throws IOException {
poke2 poke2;
poke2= new poke2();
poke2.getResult();
while(true){
System.out.println("请选择操作:\n1.继续选牌\n2.结束程序");
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
switch(a){
case 1:
poke2 = new poke2();
poke2.getResult();
break;
case 2:
System.out.print("程序已经结束!");
System.exit(0);
default :
System.exit(0);
}
}
}
}
class poke2{
public void getResult() throws IOException {
final int NUMBER_OF_CARDS = 52;
int number = (int)(Math.random() * NUMBER_OF_CARDS);
System.out.print("The card you picked is ");
if (number % 13 == 0)
System.out.print("Ace of ");
else if (number % 13 == 10)
System.out.print("Jack of ");
else if (number % 13 == 11)
System.out.print("Queen of ");
else if (number % 13 == 12)
System.out.print("King of ");
else
System.out.print((number % 13) + " of ");
if (number / 13 == 0)
System.out.println("Clubs");
else if (number / 13 == 1)
System.out.println("Diamonds");
else if (number / 13 == 2)
System.out.println("Hearts");
else if (number / 13 == 3)
System.out.println("Spades");
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-09-15
展开全部
楼主,不如先讲讲程序存在的问题。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询