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;
}