我想用java在命令行中读取值,但我无法做到

时间:2015-08-09 04:43:37

标签: java

这是我的程序

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.util.Scanner;
public class Solution1 {
 public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
  Scanner in = new Scanner(new InputStreamReader(System.in));
   System.out.println("Enter the INTEGER");
int num = in.nextInt();
  System.out.println("Enter the double");
double d=in.nextDouble();
  System.out.println("Enter the String");
String s=" ";
        s=in.nextLine();
        System.out.println("String:" + s);
        System.out.println("Double:"+d);
        System.out.println("Int:"+num);
    }

}

输出

输入INTEGER 1 输入双精度数 1.1 输入字符串 串: 双:1.1 INT:1

我应该显示字符串值,但我无法做到请帮帮我

2 个答案:

答案 0 :(得分:1)

在阅读下面的字符串之前加上额外的nextLine

in.nextLine();
s=in.nextLine();

答案 1 :(得分:0)

试试这个:

<script src="../jquery/jquery-1.8.2.js"></script>
<script src="../jquery/jquery.ui.effect.js"></script>
<script>
  $(function() {
    $('button.btn').on('click', function() {
      if ('create_task' == $(this).val()) {
        for (var i = 0; i < $('.validate').length; i++) {
          if ("" == $('.validate').eq(i).val()) {
            $('.validate').eq(i).addClass('invalid');
          } else {
            $('.validate').eq(i).removeClass('invalid');
          }
      }
      return false;
   }         
  });
</script>
<main>
    <form>
       <div class="row">
          <div class="input-field col s6">
             <input name="name" type="text" class="validate">
             <label class="active" for="task_name">Task Name</label>
          </div>
       </div>

       <button class="btn" type="submit"  value="create_task" name="createTask">Create Task</button>
    </form> 
</main>