gpt4 book ai didi

java扫描仪在线检测3个单词

转载 作者:行者123 更新时间:2023-12-01 18:49:28 25 4
gpt4 key购买 nike

我正在尝试编写一个小程序,该程序将使用扫描仪检查是否有下一行(在 while 循环中),然后可能使用另一个程序来检查该行上的单词是否为 tab appart 并且有 3 个字符串(使用构造函数创建一个对象),因此三个字符串将是产品名称制造商 Brcode

EG:轮胎17x60固特异458765464

某某

我对此有点困惑,所以任何帮助将不胜感激

最佳答案

你可以试试这个:

  public static void main (String[] args) throws java.lang.Exception
{
String str = "Tyre17x60 Goodyear 458765464";
InputStream is = new ByteArrayInputStream(str.getBytes());
Scanner sc = new Scanner(is);
sc.useDelimiter("\n");

while (sc.hasNext())
{
String[] tmp = sc.next().split("\t");
if (tmp.length == 3)
System.out.println("Text contains 3 parts separated with tabs");
else
System.out.println("Text is not well formated");

// save data
//productName = tmp[0];
//manufacturer = tmp[1];
//brcode = tmp[2];

}
}

关于java扫描仪在线检测3个单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16278172/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com