小编har*_*ari的帖子

java类和jar之间的区别

java类文件和jar文件有什么区别?

java jar class

45
推荐指数
3
解决办法
3万
查看次数

输入的时间限制

假设我有一个代码,它要求用户提供一些输入,如下所示:

for (condition) {
System.out.println("Please give some input");
System.in.read();
} //lets say this loop repeats 3 times and i face a problem during second iteration
Run Code Online (Sandbox Code Playgroud)

但我想给用户一个60秒的时间限制,然后抛出异常(在这种情况下,我认为它TimeOutException).我怎么做?

java eclipse

7
推荐指数
1
解决办法
1万
查看次数

System.out.println()的替代语句

除了Java中的System.out.println()语句外,有人可以通过提供其他打印方式来帮助我吗?

java printing

4
推荐指数
1
解决办法
1万
查看次数

期望这个循环是无限的,但事实并非如此

这是我的Java代码:

public class Prog1 {
    public static void main(String[] args) {
        int x = 5;
        while (x > 1) { 
            x = x + 1;
            if (x < 3)
                System.out.println("small x");   
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是输出:

small x
Run Code Online (Sandbox Code Playgroud)

我期待一个无限循环...任何想法为什么它这样做?

java

3
推荐指数
1
解决办法
421
查看次数

异常处理冒险

我有以下代码框架

try {    
...    
...    
sysout("Please provide an input: ");
Thread.sleep(10000); //10 secs time given to the user to give the input. If the user doesn't enter the input it is throwing the exception, which is not being handled (with the custom message)
interact();  //This is a method that belongs to **expectj.Spawn** class
...
...    
} catch (Exception e) {

    System.out.println("You have not given any input!Please try again!");

}
Run Code Online (Sandbox Code Playgroud)

但我仍然得到以下输出 -

Exception in thread "ExpectJ Stream Piper" java.nio.channels.IllegalBlockingModeException

at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:39) …
Run Code Online (Sandbox Code Playgroud)

java exception-handling try-catch

2
推荐指数
1
解决办法
323
查看次数

在JSP中显示文本框中的双引号

我编写了一个包含文本框和按钮的小JSP页面.我试图做的是在我点击按钮后显示我在文本框中写的任何内容(这是一个字符串).它适用于所有场景,但不适用于我将字符串放在双引号("")中的一种情况.我有什么方法可以做到这一点吗?

例如:如果我在文本框中写入 abcd,它可以正常工作.但如果我写 "abcd"(即使用双引号),则双引号内的文本不会显示.

我理解为什么会这样(例如:如果我们在文本框中写abcd,它被视为"abcd",如果我在文本框中写"abcd",它被视为"abcd""),但不能找不到解决方案.

或者根本没有解决方案?

java jsp

1
推荐指数
1
解决办法
2793
查看次数

Shell脚本中的Nested-If语句

这是我的脚本:

echo "Name"

read name

if [ "$name" == "abcd" ]; then

 echo "Password"

 read password

 if [ "$password == "pwd" ]; then

  echo "Hello"

 else

  echo "Wrong password"

 fi

else

 echo "wrong username"

fi
Run Code Online (Sandbox Code Playgroud)

这是我运行时得到的输出:

sh hello.sh

Name

abcd

hello.sh: line 14: unexpected EOF while looking for matching `"'

hello.sh: line 16: syntax error: unexpected end of file

这里有什么想法吗?这可能是一个非常愚蠢的,但我浪费了将近一个小时.

unix shell nested-if

0
推荐指数
1
解决办法
7万
查看次数

访问器方法的用法

这是我的包含setter和getter的类

package Pack;

public class Details {

String FirstName,LastName,City,Country;

    public Details(String firstName, String lastName, String city,
            String country) {
        super();
        FirstName = firstName;
        LastName = lastName;
        City = city;
        Country = country;
    }

    public String getFirstName() {
        return FirstName;
    }

    public void setFirstName(String firstName) {
        FirstName = firstName;
    }

    public String getLastName() {
        return LastName;
    }

    public void setLastName(String lastName) {
        LastName = lastName;
    }

    public String getCity() {
        return City;
    }

    public void setCity(String city) {
        City = city; …
Run Code Online (Sandbox Code Playgroud)

java getter-setter

0
推荐指数
1
解决办法
155
查看次数

ClassCastException冒险

我有 -

class A {
    // contains certain set() and get() methods
}

class B extends A {
    public A getAotherMethod() {
      A a = new A();
      // Contains some logic
      return a
      }
}

class C extends B {
    // contains certain set() and get() methods
}

class D {
    public Object getMethod() {

      B b = new B();
      // Contains some logic
      return b.getAnotherMethod()
     }
}


public static void main(String[] args) {
    A a = new A();
    B …
Run Code Online (Sandbox Code Playgroud)

java classcastexception

0
推荐指数
1
解决办法
92
查看次数

同步冒险

如果我遇到一种情况,我必须使我的Java程序中的每个方法同步,这会影响我的代码的性能吗?

java synchronized

-1
推荐指数
1
解决办法
110
查看次数