代码编辑辅助 import java.util.*; 公共级塔罗卡 { 公共静态void main(字符串[]args) { 扫描仪=新的扫描仪(System.in); 数字(); int a=占位符; 数字(); int b=占位符; 数字(); int c=占位符; 数字(); int d=占位符; 整数合计=a+b+c+d; if(总计13); { 卡片类型=甲板。下一层(2); 如果(cardtype==0) { System.out.println(“你的塔罗是钻石之王”); } 如果(cardtype==1) { System.out.println(“你的塔罗是钻石女王”); } 如果(cardtype==2) { System.out.println(“你的塔罗是钻石杰克”); } } 如果(卡片类型

代码编辑辅助 import java.util.*; 公共级塔罗卡 { 公共静态void main(字符串[]args) { 扫描仪=新的扫描仪(System.in); 数字(); int a=占位符; 数字(); int b=占位符; 数字(); int c=占位符; 数字(); int d=占位符; 整数合计=a+b+c+d; if(总计13); { 卡片类型=甲板。下一层(2); 如果(cardtype==0) { System.out.println(“你的塔罗是钻石之王”); } 如果(cardtype==1) { System.out.println(“你的塔罗是钻石女王”); } 如果(cardtype==2) { System.out.println(“你的塔罗是钻石杰克”); } } 如果(卡片类型,java,Java,这段代码运行时,我的问题是它没有按我希望的方式运行。我想让if语句和方法只打印出一个塔罗牌。现在,当程序运行时,它会打印出所有塔罗牌。我认为我的错误在于我如何构造我的if语句,有什么建议吗?你的if和else条件构造不正确。ifelse的正确语法如下: import java.util.*; public class TarotCard { public static void main(String[] args) { Scanner scanner = new Scanne

这段代码运行时,我的问题是它没有按我希望的方式运行。我想让if语句和方法只打印出一个塔罗牌。现在,当程序运行时,它会打印出所有塔罗牌。我认为我的错误在于我如何构造我的if语句,有什么建议吗?

你的
if
else
条件构造不正确。
if
else
的正确语法如下:

import java.util.*;
public class TarotCard
{
   public static void main(String[] args)
   {
   Scanner scanner = new Scanner(System.in);
   Number();
   int a = placeholder;
   Number();
   int b = placeholder;
   Number();
   int c = placeholder;
   Number();
   int d = placeholder;
   int total = a + b + c + d;
   if (toatal <= 9)
      {
      Hearts();
      }
   else
      {
      if (total <= 18)
      {
      Spades();
      }
      else
         {
         if(total <= 27)
            {
            Clubs();
            }
         else
            {
            Diamonds();
            }
         }
      }
   }
}

  public int Number()
  {
  System.out.println("please enter a one digit number");
 import java.util.*;
public class TarotCard
{
   public static void main(String[] args)
   {
   Scanner scanner = new Scanner(System.in);
   int placeholder = 0;
   Number(placeholder, scanner);
   int a = placeholder;
   int total = a;
   Number(placeholder, scanner);
   int b = placeholder;
   total = b + total;
   Number(placeholder, scanner);
   int c = placeholder;
   total = c + total;
   Number(placeholder , scanner);
   int d = placeholder;
   total = d + total;
   if(total <= 9)
      {
      Hearts();
      }
   if(total > 9 && total <= 18)
      {
      Clubs();
      }
   if(total > 18 && total <= 27)
      {
      Spades();
      }
   if(total > 27 && total <= 36)
      {
      Diamonds();
      }


   }


  public static int Number(int placeholder,Scanner scanner)
  {
  System.out.println("please enter a one digit number");
  placeholder = scanner.nextInt();
  return placeholder;
  }

  public static void Hearts()
  {
  Random deck = new Random();
  int cardtype = deck.nextInt(52)+1;
         if(cardtype > 13);
            {
            cardtype = deck.nextInt(2); 
            if(cardtype == 0)
               {
               System.out.println("your tarrot is king of hearts");
               }
            if(cardtype == 1)
               {
               System.out.println("your tarrot is queen of hearts");
               }
            if(cardtype == 2)
               {
               System.out.println("your tarrot is jack of hearts");
               }
            }
         if(cardtype < 12);
            {
            cardtype = deck.nextInt(10)+1;
            if(cardtype == 1);
               {
               System.out.println("your tarot is ace of hearts");
               }
            if(cardtype == 2);
               {
               System.out.println("your tarot is two of hearts");
               }
            if(cardtype == 3);
               {
               System.out.println("your tarot is three of hearts");
               }
            if(cardtype == 4);
               {
               System.out.println("your tarrot is four of hearts");
               }
            if(cardtype == 5);
               {
               System.out.println("your tarrot is 5 of hearts");
               }
            if(cardtype == 6);
               {
               System.out.println("your tarrot is 6 of hearts");
               }
            if(cardtype == 7);
               {
               System.out.println("your tarrot is 7 of hearts");
               }
            if(cardtype == 8);
               {
               System.out.println("your tarrot is 8 of hearts");
               }
            if(cardtype == 9);
               {
               System.out.println("your tarrot is 9 of hearts");
               }
            if(cardtype == 10);
               {
               System.out.println("your tarrot is 10 of hearts");
               }
            }

  }
  public static void Spades()
  {
  Random deck = new Random();
  int cardtype = deck.nextInt(52)+1;
         if(cardtype > 13);
            {
            cardtype = deck.nextInt(2); 
            if (cardtype == 0)
               {
               System.out.println("your tarrot is king of spades");
               }
            if (cardtype == 1)
               {
               System.out.println("your tarrot is queen of spades");
               }
            if (cardtype == 2)
               {
               System.out.println("your tarrot is jack of spades");
               }
            }
         if(cardtype < 12);
            {
            cardtype = deck.nextInt(10)+1;
            if (cardtype == 1);
               {
               System.out.println("your tarot is ace of spades");
               }
            if (cardtype == 2);
               {
               System.out.println("your tarot is two of spades");
               }
            if (cardtype == 3);
               {
               System.out.println("your tarot is three of spades");
               }
            if (cardtype == 4);
               {
               System.out.println("your tarrot is four of spades");
               }
            if (cardtype == 5);
               {
               System.out.println("your tarrot is 5 of spades");
               }
            if (cardtype == 6);
               {
               System.out.println("your tarrot is 6 of spades");
               }
            if (cardtype == 7);
               {
               System.out.println("your tarrot is 7 of spades");
               }
            if (cardtype == 8);
               {
               System.out.println("your tarrot is 8 of spades");
               }
            if (cardtype == 9);
               {
               System.out.println("your tarrot is 9 of spades");
               }
            if (cardtype == 10);
               {
               System.out.println("your tarrot is 10 of spades");
               }
            }  
  }
  public static void Clubs()
  {
  Random deck = new Random();
  int cardtype = deck.nextInt(52)+1;
         if(cardtype > 13);
            {
            cardtype = deck.nextInt(2); 
            if (cardtype == 0)
               {
               System.out.println("your tarrot is king of clubs");
               }
            if (cardtype == 1)
               {
               System.out.println("your tarrot is queen of clubs");
               }
            if (cardtype == 2)
               {
               System.out.println("your tarrot is jack of clubs");
               }
            }
         if(cardtype < 12);
            {
            cardtype = deck.nextInt(10)+1;
            if (cardtype == 1);
               {
               System.out.println("your tarot is ace of clubs");
               }
            if (cardtype == 2);
               {
               System.out.println("your tarot is two of clubs");
               }
            if (cardtype == 3);
               {
               System.out.println("your tarot is three of clubs");
               }
            if (cardtype == 4);
               {
               System.out.println("your tarrot is four of clubs");
               }
            if (cardtype == 5);
               {
               System.out.println("your tarrot is 5 of clubs");
               }
            if (cardtype == 6);
               {
               System.out.println("your tarrot is 6 of clubs");
               }
            if (cardtype == 7);
               {
               System.out.println("your tarrot is 7 of clubs");
               }
            if (cardtype == 8);
               {
               System.out.println("your tarrot is 8 of clubs");
               }
            if (cardtype == 9);
               {
               System.out.println("your tarrot is 9 of clubs");
               }
            if (cardtype == 10);
               {
               System.out.println("your tarrot is 10 of clubs");
               }
            }
  }
  public static void Diamonds()
  {
  Random deck = new Random();
  int cardtype = deck.nextInt(52)+1;
         if(cardtype > 13);
            {
            cardtype = deck.nextInt(2); 
            if (cardtype == 0)
               {
               System.out.println("your tarrot is king of diamonds");
               }
            if (cardtype == 1)
               {
               System.out.println("your tarrot is queen of diamonds");
               }
            if (cardtype == 2)
               {
               System.out.println("your tarrot is jack of diamonds");
               }
            }
         if(cardtype < 12);
            {
            cardtype = deck.nextInt(10)+1;
            if (cardtype == 1);
               {
               System.out.println("your tarot is ace of diamonds");
               }
            if (cardtype == 2);
               {
               System.out.println("your tarot is two of diamonds");
               }
            if (cardtype == 3);
               {
               System.out.println("your tarot is three of diamonds");
               }
            if (cardtype == 4);
               {
               System.out.println("your tarrot is four of diamonds");
               }
            if (cardtype == 5);
               {
               System.out.println("your tarrot is 5 of diamonds");
               }
            if (cardtype == 6);
               {
               System.out.println("your tarrot is 6 of diamonds");
               }
            if (cardtype == 7);
               {
               System.out.println("your tarrot is 7 of diamonds");
               }
            if (cardtype == 8);
               {
               System.out.println("your tarrot is 8 of diamonds");
               }
            if (cardtype == 9);
               {
               System.out.println("your tarrot is 9 of diamonds");
               }
            if (cardtype == 10);
               {
               System.out.println("your tarrot is 10 of diamonds");
               }
            }

  }
}
请尝试此版本的代码:

if (condition1) {
    // do something
}
else if (condition2) {
    // do something else
}
else {
    // other
}
publicstaticvoidmain(字符串[]args){
扫描仪=新的扫描仪(System.in);
数字();
int a=占位符;
数字();
int b=占位符;
数字();
int c=占位符;
数字();
int d=占位符;
整数合计=a+b+c+d;

如果(toatal必须将Number()方法的返回值赋给int变量,则参数占位符不会更改main类中占位符的值

public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    Number();
    int a = placeholder;
    Number();
    int b = placeholder;
    Number();
    int c = placeholder;
    Number();
    int d = placeholder;
    int total = a + b + c + d;

    if (toatal <= 9) {
        Hearts();
    }
    else if (total <= 18) {
        Spades();
    }
    else if (total <= 27) {
        Clubs();
    }
    else {
        Diamonds();
    }
}
publicstaticvoidmain(字符串[]args)
{
int a=数字();
整数总计=a;
int b=数字();
总计=b+总计;
int c=数字();
总计=c+总计;
int d=数字();
总计=d+总计;

if(total 9&&total 18&&total 27&&total删除
if
语句后的分号,例如:
if(cardtype==8);
if(cardtype==8)
public static void main(String[] args)
   {
   int a = Number();
   int total = a;      
   int b = Number();
   total = b + total;      
   int c = Number();
   total = c + total;
   int d =  Number();
   total = d + total;
   if(total <= 9)
      {
      Hearts();
      }
   if(total > 9 && total <= 18)
      {
      Clubs();
      }
   if(total > 18 && total <= 27)
      {
      Spades();
      }
   if(total > 27 && total <= 36)
      {
      Diamonds();
      }
   }


  public static int Number()
  {
      Scanner scanner = new Scanner(System.in);
      System.out.println("please enter a one digit number");
      return scanner.nextInt();
  }