package com.secutiry.rsa;
import java.util.Scanner;
public class Prtest {
public String Phintx(){
Scanner cc =new Scanner(System.in);
//下马这行会报错,选择try catch 或者 throw declaration
//选择try catch 则无法return ,选择throw declaration 则在主方法中会报异常
String tt =new String(cc.next().getBytes(),"utf-8");
return tt;
}
public static void main(String[] args) {
Prtest prtest = new Prtest();
String tx = prtest.Phintx();
System.out.println(tx);
}
}
cc.next()没有获取到字符串吧,你可以用try catch吃掉:
Scanner cc =new Scanner(System.in);
String tt = "";
try {
//下马这行会报错,选择try catch 或者 throw declaration
//选择try catch 则无法return ,选择throw declaration 则在主方法中会报异常
String tt =new String(cc.next().getBytes(),"utf-8");
} catch {}
return tt;
}
编码和输出要保持一致才行