मैं अपने nirc
संख्या में कुंजी रखना चाहता हूं उदा। S1234567I
और फिर individualy 1234567
डाल आदि indiv1
charAt(1)
के रूप में के रूप में एक पूर्णांक, indiv2
charAt(2)
के रूप में, indiv
charAt(3)
के रूप में, के रूप में हालांकि, जब मैं नीचे दिए गए कोड का उपयोग करें, मैं भी पहले नंबर बाहर निकलना नहीं कर पा रहे? कोई उपाय?जावा: charAt int में कनवर्ट करें?
Scanner console = new Scanner(System.in);
System.out.println("Enter your NRIC number: ");
String nric = console.nextLine();
int indiv1 = nric.charAt(1);
System.out.println(indiv1);
Integer.parseInt एक स्ट्रिंग है, न कि चार लेता है। –
हे ओप्स Integer.parseInt (Character.toString (nric.charAt (1))); : पी या Integer.parseInt (nric.substr (1, 1)); लेकिन गंभीरता से, बस जॉन स्कीट के जवाब के साथ जाओ। – jonathanasdf