我在Java中这样做。
我在编译时遇到问题。
它表示 .class预期
有什么不对的请纠正我,我是Java新手
import java.io.*;
import java.math.*;
class name {
public static void convertToArray(String pin){
StringBuilder sB = new StringBuilder();
sB.append(pin);
String toConvert = sB.toString();
int [] splittedValue = new int [toConvert.length()];
for(int i = 0; i < toConvert.length(); i++){
splittedValue[i] = Character.getNumericValue(pin.charAt(i));
}
return splittedValue[];
}
public static void Print(int n) {
System.out.println(n);
}
public static void main(String args[])throws IOException {
InputStreamReader ir = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(ir);
int pin1[], i = 0;String Name1, Name2, Name3;
String Pin;
String Names[][] ={ {"Mr.","Mrs.","Miss.","Dr.","Sir","Late","Professor","Gadha","Master","Teacher"},{"Abhigyan","Akashdeep","Anish","Adarsh","Ashutosh","","Anik","Shivam","",""},{"Saha","Mukkherjee","Pandey","Shaw","Bannerjee","Dey","Gupta","Singh","",""} };
System.out.println("Enter your 3 digit code name :");
Pin=br.readLine();
convertToArray(Pin);
Name1=Names[0][pinExtracted[0]]; Name2=Names[1][pinExtracted[1]]; Name3=Names[2][pinExtracted[2]];
System.out.println(Name1+" "+Name2+" "+Name3);
}
}
答案 0 :(得分:1)
我认为你的输出只会是正确的。
import java.io.*;
import java.math.*;
public class name {
public static void convertToArray(String pin){
StringBuilder sB = new StringBuilder();
sB.append(pin);
String toConvert = sB.toString();
int [] splittedValue = new int [toConvert.length()];
for(int i = 0; i < toConvert.length(); i++){
splittedValue[i] = Character.getNumericValue(pin.charAt(i));
}
// return splittedValue[];
}
public static void Print(int n) {
System.out.println(n);
}
public static void main(String args[])throws IOException {
InputStreamReader ir = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(ir);
String Name1, Name2, Name3;
String Pin;
String Names[][] ={ {"Mr.","Mrs.","Miss.","Dr.","Sir","Late","Professor","Gadha","Master","Teacher"},{"Abhigyan","Akashdeep","Anish","Adarsh","Ashutosh","","Anik","Shivam","",""},{"Saha","Mukkherjee","Pandey","Shaw","Bannerjee","Dey","Gupta","Singh","",""} };
System.out.println("Enter your 3 digit code name :");
Pin=br.readLine();
convertToArray(Pin);
Name1=Names[0][0]; Name2=Names[1][1]; Name3=Names[2][2];
System.out.println(Name1+" "+Name2+" "+Name3);
}
}
<强>输出:强>
输入您的3位数代码:
012
先生。 Akashdeep Pandey
答案 1 :(得分:0)
错误 .class预期是由
引起的return splittedValue[];
只有在声明数组变量时才必须使用[]
,因此请将其更改为
return splittedValue;
请注意,您的convertToArray
方法应该有签名
public static int[] convertToArray(String pin){
主方法中有更多错误,您不要声明变量pinExtracted
因此写
int[] pinExtracted = convertToArray(Pin);