[問題] 新手程式問題
我的目的是判斷輸入字串裡面的數字結合是不是1234
EX:1sd2fdf3hg4 的數字結合就是1234
可是我就算輸入1234 他還是說數字結合不是1234= =
可是我print sb出來 明明就是1234阿
import java.util.*;
public class JB07_PT52 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String password=sc.nextLine();
StringBuffer sb=new StringBuffer();
for(int i=0;i<password.length();i++){
if(password.charAt(i)>=48&&password.charAt(i)<=57)
sb.append(password.charAt(i));
}
// System.out.println(sb);
if(sb.equals("1234")) System.out.println("輸入字串中數字的結合是1234");
else System.out.println("輸入字串中數字的結合不是1234");
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 125.228.248.172
※ 編輯: e40614 來自: 125.228.248.172 (08/26 20:31)
→
08/26 20:38, , 1F
08/26 20:38, 1F
→
08/26 20:59, , 2F
08/26 20:59, 2F
→
08/26 21:00, , 3F
08/26 21:00, 3F
推
08/26 21:08, , 4F
08/26 21:08, 4F
推
08/26 21:41, , 5F
08/26 21:41, 5F
→
08/26 21:50, , 6F
08/26 21:50, 6F