【发布时间】:2014-06-04 16:54:13
【问题描述】:
Java 字符串包含两种类型的单词。 第一个类型的词是:
Wx1,Wx2,Wx3,Wx4,Wx5,Wx6, Wx7 etc.
第二种类型的词是:
Wy1,Wy2 etc.
给定
String str= "Wx1 Wx2 Wy1 Wx3 Wx4 Wy2 Wx5 Wx7 Wx8"
第一种由function1()处理,第二种由function2()处理,function3()进一步处理function1()的级联输出。
function1(Wx1) gives String S1
function1(Wx2) gives String S2
String S12= S1 + S2;
function3(S12) returns String str1
function2(Wy1) gives String Y1
function1(Wx3) gives String S3
function1(Wx4) gives String S4
String S34= S3 + S4;
function3(S34) returns String str2
function2(Wy2) gives String Y2
function1(Wx5) gives String S5
function1(Wx6) gives String S6
function1(Wx7) gives String S7
function1(Wx8) gives String S8
String S5678 = S5 + S6 + S7 + S8
function3(S5678) returns String str3
String output = str1 + Y1+ str2 + Y2 + str3;
This is the whole logic my program.
我在最后一步很困惑,以塑造在哪里以及如何调用 function3() 的循环:
for(int i=0; i<Words.length; i++){
if Word[i]= Type1??????????{ doThis(); ?????
//somewhere here I have to call function3(), how the program will judge that the next word is of type2, hence function3 is to be called here.// WHERE AND HOW TO CALL function3();
}
else {doThat();
}
作为编程新手,我需要帮助来形成循环的逻辑。
【问题讨论】:
-
您正在寻找模式。
-
type 1 words 和 type 2 words 有什么区别?当您可以用英语或您的母语回答该问题时,您就可以将您的需求转化为代码。
-
第一种以 1h,2h,5k 等数字开头,第二种以 fsh,ggk,nas,ilk 等字母开头。