- 我创建了一个名为showCharacter的方法。该方法获取一个字符串,并显示该字符串中给定位置的字符。这是该方法的代码:
Select
Equip,Count like Description,from
WorkOrder (nolock)
where
DateTm Between DATEADD(month,DATEDIFF(month,getDate()),0) and DATEADD(month,-1,-1)
Group by
Equip,Description
order by
Equip Asc
- 主要,我想要求用户输入一个字符串,然后要求用户输入一个数字,该数字指定该字符串中的位置(第一个字母,第二个字母,第五个字母等)。
我遇到的问题毕竟是要打印到屏幕上的“在USER_ENTRY位置的字母是:CHARactER_FROM_THE_METHOD_I_CREATED_EARLIER。”
这是我主要方法中的当前代码:
public static void showCharacter(String userStr1,byte charLoc)
{
System.out.println(userStr1.charAt(charLoc));
}
我尝试写:
public static void main(String[] args) {
// TODO code application logic here
Scanner k = new Scanner(System.in);
System.out.println("Please enter a String");
String str = k.nextLine();
int strLen = str.length();
System.out.println("Please enter the character's position");
byte i = k.nextByte();
while (i <0 || i > (strLen -1))
{
System.out.println("Invalid Position. Enter a valid position");
i = k.nextByte();
}
showCharacter(str,i);
}
有什么想法吗?
谢谢!