简体   繁体   English

Java错误:线程“ main”中的异常java.lang.RuntimeException

[英]Java Errors: Exception in thread “main” java.lang.RuntimeException

I am running a Program in CMD. 我正在CMD中运行程序。

I am using 2 methods to have it print out like the below: 我正在使用2种方法将其打印出来,如下所示:

Print all characters between a and w: 打印a和w之间的所有字符:
abcdefghij abcdefghij
klmnopqst 克拉姆诺普斯特
uvw 紫外线

Below is what I have so far ... But I can not get past here. 以下是我到目前为止所拥有的...但是我无法在这里过去。 I keep getting all sorts of errors. 我不断收到各种各样的错误。

public class Letters{
public static void main (String[] args) {
System.out.println("Print all characters between a and w");

for (char i = 0; i <= 10; i++) {
String myrow = printChars('a','w');
System.out.println(myrow);
}
}
public static void printChars (char c1, char c2){


}
}

First of, I recommend to properly indent your code, making it easier to read. 首先,我建议适当缩进代码,以使其更易于阅读。 Second as you are using char you can just check against the value of the character. 其次,在使用char时,您可以仅检查字符的值。 char c = 'a' like that. char c = 'a'像这样。 If you increment c it then has the value of b . 如果增加c,则其值为b

public class Letters
{
    public static void main (String[] args) {
        System.out.println("Print all characters between a and w");

        for (char c = 'a'; c <= 'w'; c++) {
            System.out.print(c);
            if ((c+1 - 'a') % 10 == 0) {
                System.out.println();
            }
        }

        System.out.println("\n");

        printChars ('d','z');
    }

    public static void printChars (char c1, char c2) {
        // no valid range, can also add checks to see if they are actual letters
        if (c1 > c2) {
            return;
        }

        System.out.println("Print all characters between " + c1 + " and " + c2);
        for (char c = c1; c <= c2; c++) {
            System.out.print(c);
            if ((c+1 - c1) % 10 == 0) {
                System.out.println();
            }
        }
    }
}

This part checks what iteration is currently being done, it then checks if that iteration is divisible by 10, to add a new line, if not, move along. 这部分检查当前正在执行的迭代,然后检查该迭代是否可被10整除,以添加新行,否则将继续。

if ((c+1 - 'a') % 10 == 0) {
    System.out.println();
}
public static void main( String[] args )
{
    char c1='a';
    char c2='w';

    String str= "a b c d e f g h i j k l m n o p q s t u v w";
    Pattern compile = Pattern.compile(".*"+c1+"(.*)"+c2+".*");
    Matcher matcher = compile.matcher(str);
    boolean found = matcher.find();
    System.out.println("found:"+ found);
    if (found) System.out.println(matcher.group(1));

}

E:\\Java>jdk1.8.0_111\\bin>java -jar selenium-server-standalone-3.0.0.jar -htmlsuite " *firefox "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe" " https://www.google.com/ " "E:\\Selenium\\newsuite.html" "E:\\Selenium\\result.html" E:\\ Java> jdk1.8.0_111 \\ bin> java -jar selenium-server-standalone-3.0.0.jar -htmlsuite“ * firefox” C:\\ Program Files(x86)\\ Mozilla Firefox \\ firefox.exe“” https ://www.google.com/ “” E:\\ Selenium \\ newsuite.html“” E:\\ Selenium \\ result.html“

i got the above mentioned error.please help 我收到了上述error.please帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 线程“ main”中的异常java.lang.RuntimeException:无法编译的源代码 - Exception in thread “main” java.lang.RuntimeException: Uncompilable source code 线程“main”中的异常 java.lang.RuntimeException:尚未实现 - Exception in thread "main" java.lang.RuntimeException: Not yet implemented 线程“main”中的异常 java.lang.RuntimeException: Stub XmlPullParserFactory - Exception in thread "main" java.lang.RuntimeException: Stub XmlPullParserFactory 线程“主”java.lang.RuntimeException 中的异常:矩阵是奇异的 - Exception in thread “main” java.lang.RuntimeException: Matrix is singular 线程“main”中的异常java.lang.RuntimeException:找不到OpenGL上下文 - Exception in thread “main” java.lang.RuntimeException: No OpenGL context found 线程“main”中的异常java.lang.RuntimeException:Stub - Exception in thread “main” java.lang.RuntimeException: Stub 线程“主”java.lang.RuntimeException 中的错误异常 - Error Exception in thread "main" java.lang.RuntimeException 致命异常:主java.lang.RuntimeException: - FATAL EXCEPTION: Main java.lang.RuntimeException: 由 java.lang.RuntimeException 引起的线程“main”java.lang.ExceptionInInitializerError 中的异常:无法实例 KieServices - Exception in thread "main" java.lang.ExceptionInInitializerError caused by java.lang.RuntimeException: Unable to instance KieServices 线程“主”中的Java异常java.lang.RuntimeException:无法编译的源代码-错误的树类型: - Java Exception in thread “main” java.lang.RuntimeException: Uncompilable source code - Erroneous tree type:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM