1 Star 0 Fork 2

谢继业/teamdemo

forked from 贾沈杰/teamdemo 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Strings.java 878 Bytes
一键复制 编辑 原始数据 按行查看 历史
贾沈杰 提交于 2020-06-06 16:50 . 由贾沈杰提交
import java.util.Scanner;
import java.lang.String;
/**
A program reads in a string, followed by an integer n,
where the value of the integer should be smaller than the
length of the string. The program then prints out the last
n characters of the string.
*/
public class Strings
{
public static void main (String[] args)
{
// Display prompt for string of characters
System.out.println("Please enter a string: ");
// Read string
Scanner in = new Scanner(System.in);
String str = in.nextLine();
// Display prompt for integer n
System.out.println("Please enter a value for n: ");
// Read n
int n = in.nextInt();
// Print last n characters of string
// Your work here
String subStr = new String();
subStr = str.substring(str.length()-n);
System.out.println(subStr);
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/xjyng/teamdemo.git
git@gitee.com:xjyng/teamdemo.git
xjyng
teamdemo
teamdemo
master

搜索帮助