第1个回答 2010-09-17
import java.util.Scanner;
public class Qh{
public static void main(String[] args){
Scanner input=new Scanner(System.in);
String pd;
int i=0;
do{
System.out.println("请输入第"+(i+1)+"个参数:");
String cs[]=new String[i+1];
cs[i]=input.next();
System.out.println("目前该数组的长度为:"+(i+1));
i++;
System.out.println("请问还有要输入的吗?Y/N");
pd=input.next();
}while(pd.equals("Y"));
}
}
第2个回答 2010-09-17
以下这个程序应该可以说明一切:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
String str=bufferedReader.readLine();
System.out.println(str);
System.out.println(str.length());
char[] ch=str.toCharArray();
for (int i = 0; i < ch.length; i++) {
System.out.println(ch[i]);
}
System.out.println(ch.length);
}
}
第3个回答 2012-07-23
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
char[] a=new char[20];
String str=null;
str=s.next();
for(int i=0;i<str.length();i++){
a[i]=str.charAt(i);
}
for(int i=0;i<str.length();i++){
System.out.print(a[i]+"\t");
}
System.out.println();
System.out.print("输入了"+str.length()+"个字符");
}