Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用多字符';在if-else语句中是什么?_Java_Char - Fatal编程技术网

Java 使用多字符';在if-else语句中是什么?

Java 使用多字符';在if-else语句中是什么?,java,char,Java,Char,尝试检查用户输入的第一个和最后两个字母是否为基于文本的游戏的字母数据类型。我一直收到一个非对账单错误。不知道为什么会感谢任何帮助 import java.util.Scanner.*; public class name info{ public static void main(String[]args) { Scanner console= new Scanner(System.in); System.out.println("Enter Job Name:

尝试检查用户输入的第一个和最后两个字母是否为基于文本的游戏的字母数据类型。我一直收到一个非对账单错误。不知道为什么会感谢任何帮助

import java.util.Scanner.*;

public class name info{

  public static void main(String[]args) {
    Scanner console= new Scanner(System.in);
    System.out.println("Enter Job Name:");
    String JobName = console.nextInt();

    if (isLetter(str.charAt(str.length-1))&&(isLetter(str.CharAt(1)){
      system.out.println ("Job name approved");
    }
    else {
     System.out.Println(JobName+" is not a valid job name.");
    }
    System.out.Println("part 1 End");
  }
}

error: ')' expected
error:not a statement

代码中有两个问题。首先,您必须在行前加上“如果”:

(isLetter(str.charAt(str.length-1))&&(isLetter(str.CharAt(1))
所以代码是:

import java.util.Scanner.*;

public class EmploymentInfo{

  public static void main(String[]args) {
    Scanner console= new Scanner(System.in);
    System.out.println("Please enter your last name:");
    String LastName = console.nextInt();

    if(LastName.indexOf(" ")<2){ //cond1
      if (isLetter(str.charAt(str.length-1))&&(isLetter(str.CharAt(1)){ //cond2
        //What to do if condition 1 & 2 are verified
      }else{
        //What to do if only cond 1 is verified
      }//end if cond2
    }else {
        //what if cond 1 is NOT verified
    }//end if cond1
    //other code
  }
}
import java.util.Scanner.*;
公共类EmploymentInfo{
公共静态void main(字符串[]args){
扫描仪控制台=新扫描仪(System.in);
System.out.println(“请输入您的姓氏:”);
字符串LastName=console.nextInt();

如果(LastName.indexOf(“”用于检查条件的逻辑不正确。但是,我强烈建议在此处使用带有
String#matches
的正则表达式选项:

String LastName = console.nextInt();
if (lastName.matches("(?i)(?!.* .* .* )[A-Z]{2}")) {
    System.out.println("Last name approved");
else {
    System.out.Println(LastName + " is not a valid last name.");
}

在第一个条件之后,要么需要一个嵌套的if语句,要么需要一个&&或!!。也许OP是java的新特性(请参见错误)我认为最好写一些简单的解决方案,或者修复那些错误会更有帮助ofcourse@User-Upvotedon'tsayThanks如果OP的赋值禁止使用正则表达式,那么我同意你的意见。否则,最好的SO答案是…可以给出的最好答案,不管级别如何。这个答案如何检查不超过两个空格e present?@TimBiegeleisen问题是“为什么我收到的不是一个声明错误?”,而不是“我如何检查是否有不超过两个空格”……但是,正如建议的那样,我已经更新了我的答案,通过一种方法,您可以找到空格数和其他使用扫描仪的有用提示。
String LastName = console.nextInt();
if (lastName.matches("(?i)(?!.* .* .* )[A-Z]{2}")) {
    System.out.println("Last name approved");
else {
    System.out.Println(LastName + " is not a valid last name.");
}