java中输入字符串数组
比如输入字符串,中间以空格间隔,然后转化为如下的Stringtrans_set[]={"abc","abc","acde","bcdf","abcd","abcdf"};...
比如输入字符串,中间以空格间隔,然后转化为如下的
String trans_set[]={"abc","abc","acde","bcdf","abcd","abcdf"};
怎么将字符串输入到字符串数组中去 展开
String trans_set[]={"abc","abc","acde","bcdf","abcd","abcdf"};
怎么将字符串输入到字符串数组中去 展开
3个回答
展开全部
//简单的写了一个类,看看对你有没有帮助
import java.util.Scanner;
public class TransString
{
public static void main (String[] args)
{
String trans_set[]=new String[6];
System.out.println("请输入六个字符串");
Scanner sc=new Scanner(System.in);
for(int i=0;i<6;i++)
{
trans_set[i]=sc.next();
System.out.println("trans_set[i]="+trans_set[i]);
}
}
}
import java.util.Scanner;
public class TransString
{
public static void main (String[] args)
{
String trans_set[]=new String[6];
System.out.println("请输入六个字符串");
Scanner sc=new Scanner(System.in);
for(int i=0;i<6;i++)
{
trans_set[i]=sc.next();
System.out.println("trans_set[i]="+trans_set[i]);
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
package javasedemo;
import java.io.*;
public class StringDemo01 {
public static void main(String[] args) {
// TODO Auto-generated method stub
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String[] str = null;
try {
str = br.readLine().split(" ");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(int i=0;i<str.length;i++){
System.out.print(str[i] + " ");
}
}
}
import java.io.*;
public class StringDemo01 {
public static void main(String[] args) {
// TODO Auto-generated method stub
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String[] str = null;
try {
str = br.readLine().split(" ");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(int i=0;i<str.length;i++){
System.out.print(str[i] + " ");
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
比如:
String str = "input date";
String[] trans_set = str.split(" ");
这里的结果:
trans_set[0] = "input";
trans_set[1] = "date";
明白没?
String str = "input date";
String[] trans_set = str.split(" ");
这里的结果:
trans_set[0] = "input";
trans_set[1] = "date";
明白没?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询