Java for循环算法
我如何做一个循环,检查1,4次,然后移动到2,检查4次,然后移动到3,检查4次 例如:Java for循环算法,java,loops,Java,Loops,我如何做一个循环,检查1,4次,然后移动到2,检查4次,然后移动到3,检查4次 例如: //Btw, isNextFree is a boolean that returns true or false if the next line is free. while(linenumber.isNextFree()){ int linenumber=1; username = line(linenumber,usernamefile); linenumber+=1; } 所以,这个循环的作用是检
//Btw, isNextFree is a boolean that returns true or false if the next line is free.
while(linenumber.isNextFree()){
int linenumber=1;
username = line(linenumber,usernamefile);
linenumber+=1;
}
所以,这个循环的作用是检查usernamefile.txt的行号,并将该值存储在一个hashmap中,我需要检查使用该hashmap中存储的第一行中的字符串值,使用户名文件的行号1上的4个字符串与passwordfile.txt上的1个相同的passwordstring连接起来
顺便说一下,我使用的是scanner,所以line和linenumber.isNextFree不存在,它基本上就像scanner的.isNext一样。我不理解问题的第二部分,第一部分:
for(int i=1; i<4; i++)
{
for(int j=1; j<5; j++)
{
//Do somethings for check
//Example
System.out.println("It's "+ i + " = " j ");
}
System.out.println(""); //only a new line like \n
}
我希望这能有所帮助。这甚至不能编译(
linenumber
不能是什么东西和int
)我不知道你想说什么。这是胡言乱语。输出总是1到3,不像OP预期的那样
It's 1 = 1
It's 1 = 2
It's 1 = 3
It's 1 = 4
It's 2 = 1
It's 2 = 2
It's 2 = 3
It's 2 = 4
It's 3 = 1
It's 3 = 2
It's 3 = 3
It's 3 = 4