java的startswith_在Java中使用startsWith和endsWith时如何忽略大...

本文介绍了一个Java程序,该程序通过命令行接收用户输入,解析这些输入以选择绘制不同方向的直角三角形,并提供了帮助菜单和停止程序的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参见英文答案 > startsWith() method of string ignoring case????????????????????????????????????7个

这是我的代码:

public static void rightSel(Scanner scanner,char t)

{

/*if (!stopping)*/System.out.print(": ");

if (scanner.hasNextLine())

{

String orInput = scanner.nextLine;

if (orInput.equalsIgnoreCase("help")

{

System.out.println("The following commands are available:");

System.out.println(" 'help' : displays this menu");

System.out.println(" 'stop' : stops the program");

System.out.println(" 'topleft' : makes right triangle alligned left and to the top");

System.out.println(" 'topright' : makes right triangle alligned right and to the top");

System.out.println(" 'botright' : makes right triangle alligned right and to the bottom");

System.out.println(" 'botleft' : makes right triangle alligned left and to the bottom");

System.out.println("To continue, enter one of the above commands.");

}//help menu

else if (orInput.equalsIgnoreCase("stop")

{

System.out.println("Stopping the program...");

stopping = true;

}//stop command

else

{

String rawInput = orInput;

String cutInput = rawInput.trim();

if (

我想让用户了解如何输入命令,例如:右上角,右上角,右上角,左上角等.

为此,我正在尝试,在最后一次if(,检查cutInput是以“top”还是“up”开头并检查cutInput是以“left”还是“right”结束,所有这些都是不区分大小写的. 这是可能吗?

这样做的最终目的是允许用户在一行输入中从三角形的四个方向中选择一个.这是我能想到的最好的方式,但是对于一般的编程我来说还是很新的,可能会使事情变得复杂.如果我是,并且它转变为更简单的方式,请告诉我.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值