2个回答
展开全部
import java.util.*;
public class App5_8
{
public static void main(String []args)
{
System.out.println("请输入一个字符串:");
String str = new Scanner(System.in).nextLine();
System.out.println("请输入子串开始位置:");
int str1 = new Scanner(System.in).nextInt();
System.out.println("请输入子串的长度:");
int str2 = new Scanner(System.in).nextInt();
System.out.println(str.substring(str1,str1+str2));
}
}
public class App5_8
{
public static void main(String []args)
{
System.out.println("请输入一个字符串:");
String str = new Scanner(System.in).nextLine();
System.out.println("请输入子串开始位置:");
int str1 = new Scanner(System.in).nextInt();
System.out.println("请输入子串的长度:");
int str2 = new Scanner(System.in).nextInt();
System.out.println(str.substring(str1,str1+str2));
}
}
推荐于2016-05-06
展开全部
public class Substring {
public static void main(String[] args) throws Exception{
System.out.print("请输入一个字符串 ->:");
String str=readLine();
System.out.println("请输入子字符串的起始位置 ->:");
int start=Integer.parseInt(readLine());
System.out.println("请输入子字符串的长度 ->:");
int len=Integer.parseInt(readLine());
System.out.println("子字符串: "+str.substring(start,start+len));
}
private static String readLine()throws Exception{
byte[] buff=new byte[1024];
int read=System.in.read(buff);
return new String(buff,0,read).trim();
}
}
public static void main(String[] args) throws Exception{
System.out.print("请输入一个字符串 ->:");
String str=readLine();
System.out.println("请输入子字符串的起始位置 ->:");
int start=Integer.parseInt(readLine());
System.out.println("请输入子字符串的长度 ->:");
int len=Integer.parseInt(readLine());
System.out.println("子字符串: "+str.substring(start,start+len));
}
private static String readLine()throws Exception{
byte[] buff=new byte[1024];
int read=System.in.read(buff);
return new String(buff,0,read).trim();
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询