楼主的代码中,整数a 为局部变量,并不是你的输入
不知道下面这个是否符合楼主的要求    public static String str = null;
    public static Integer num = null;
    
    public static void main(String[] args) {
        System.out.println("请输入字符串");
        Scanner sc = new Scanner(System.in);
        str = sc.nextLine();
        System.out.println("请输入整数");
        num = sc.nextInt();
        System.out.println("字符串为 " + str + "\n" + "整数为 " + num);
    }

解决方案 »

  1.   


    可以提供一个 BufferedReader版本的嘛?
      

  2.   


        public static String str = null;
        public static Integer num = null;
        
        public static void main(String[] args) throws IOException {
            System.out.println("请输入字符串");
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            str = br.readLine();
            System.out.println("请输入整数");
            num = Integer.parseInt(br.readLine());
            System.out.println("字符串为 " + str + "\n" + "整数为 " + num);
        }
      

  3.   


        public static String str = null;
        public static Integer num = null;
        
        public static void main(String[] args) throws IOException {
            System.out.println("请输入字符串");
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            str = br.readLine();
            System.out.println("请输入整数");
            num = Integer.parseInt(br.readLine());
            System.out.println("字符串为 " + str + "\n" + "整数为 " + num);
        }
    public class Test {
    public static void main(String[] args) {
    String str = null;
    Integer num = null;
    System.out.println("请输入字符串");
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    str = br.readLine();
    System.out.println("请输入整数");
    num = Integer.parseInt(br.readLine());
    System.out.println("字符串为 " + str + "\n" + "整数为 " + num);
    }
    }Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    Unhandled exception type IOException
    Unhandled exception type IOException at Test.main(Test.java:14)java 版本是1.7的, 是不是必须捕捉异常才可以编译过去?java语法这么奇怪,难道异常必须捕捉? 
      

  4.   

    楼主可以捕获异常,我的代码写的简单,直接将异常抛出去了。
    public static void main(String[] args) throws IOException {
      

  5.   


        public static String str = null;
        public static Integer num = null;
        
        public static void main(String[] args) throws IOException {
            System.out.println("请输入字符串");
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            str = br.readLine();
            System.out.println("请输入整数");
            num = Integer.parseInt(br.readLine());
            System.out.println("字符串为 " + str + "\n" + "整数为 " + num);
        }
    public class Test {
    public static void main(String[] args) {
    String str = null;
    Integer num = null;
    System.out.println("请输入字符串");
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    str = br.readLine();
    System.out.println("请输入整数");
    num = Integer.parseInt(br.readLine());
    System.out.println("字符串为 " + str + "\n" + "整数为 " + num);
    }
    }Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    Unhandled exception type IOException
    Unhandled exception type IOException at Test.main(Test.java:14)java 版本是1.7的, 是不是必须捕捉异常才可以编译过去?java语法这么奇怪,难道异常必须捕捉? 

    package com.foo.proxy;import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;public class Test1 {
    public static void main(String[] args) throws IOException {
    String str = null;
    Integer num = null;
    System.out.println("请输入字符串");
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    str = br.readLine();
    System.out.println("请输入整数");
    num = Integer.parseInt(br.readLine());
    System.out.println("字符串为 " + str + "\n" + "整数为 " + num);
    }
    }
    你的代码没问题啊! 你看一下你的14行对应的是哪一条语句~