void menu() {
print();
Scanner input = new Scanner( System.in );
while(true) {
String s = input.next();
switch (s) {
case "m": print(); continue;
case "s": stat(); break;
case "[A-Z]{1}[a-z]{2}\\d{1,}": filminfo( s ); break;
case "Jur1": filminfo(s); break; //For debugging - this worked fine
case "q": ; return;
}
}
}
Run Code Online (Sandbox Code Playgroud)
似乎我的正则表达式已关闭或我在案例陈述中没有正确使用它.我想要的是一个字符串:开头只有一个大写字母,后面跟着两个小写字母,后跟至少一个数字.
我已经检查了正则表达式API并尝试了三种变体(贪婪,不情愿和占有量词),却不知道它们的正确用法.还检查了String的方法,但没有找到与我的需求相关的方法.
我正在尝试重用输入法Scanner(System.in)和BufferedReader(FileReader).当用户键入"readfile"作为命令时,程序会将文件中的第一个人(即文件中的第一行)添加到列表中,但是BufferedReader卡在同一行上,因此卡在无限循环中.键盘输入
的Scanner方法就像魅力一样.
class Menu {
public static final int ARRAYINDEXFOREMAIL = 3;
private static final String NEWPERSON = "newperson";
private static final String FROMFILE = "readfile";
public static final String READFILE = "saved.txt";
private Scanner keyboardInput = new Scanner( System.in );
private String name;
private String tlf;
private String[] email;
private String [] stringTmp;
private String in;
private boolean readFromFile = false;
Menu( boolean fileRead ) {
if( fileRead ) {
readFromFile …Run Code Online (Sandbox Code Playgroud) 我已经看到可以使用多个三元条件,但是如果单个条件为真,则没有找到分配两个变量的方法.这是我试图写的方法:
int[] chkNext(int mnd, int y) {
int[] date = new int[2];
mnd = 12 ? mnd = 1, y++ : mnd++; // returns the following: "error: : expected"
date[0] = mnd, date[1] = y;
return date;
}
Run Code Online (Sandbox Code Playgroud) 我需要在Java分配中使用方法名称setNumberMeAndTheRest().
是否可以定义更短更恰当的名称,并允许通过所需名称调用该方法?
我有一个带有几个StreamFields 的抽象Wagtail模型.其中两个StreamField位于管理视图中的单独选项卡中,这些选项卡将添加到edit_handler.
class AbstractHomePage(Page):
body = StreamField(
HomePageStreamBlock(),
default=''
)
headingpanel = StreamField(
HeadingPanelStreamBlock(),
default=''
)
sidepanel = StreamField(
SidePanelStreamBlock(),
default=''
)
class Meta:
abstract = True
search_fields = Page.search_fields + [index.SearchField('body')]
content_panels = Page.content_panels + [
StreamFieldPanel('body'),
]
pagesection_panels = [
StreamFieldPanel('headingpanel'),
StreamFieldPanel('sidepanel'),
]
edit_handler = TabbedInterface([
ObjectList(content_panels),
ObjectList(pagesection_panels, heading='Page sections'),
ObjectList(Page.promote_panels),
ObjectList(Page.settings_panels, classname='settings'),
])
Run Code Online (Sandbox Code Playgroud)
我想扩展此模型并添加一个字段:
class Foo(AbstractHomePage):
extra = models.TextField()
Meta:
verbose_name='Foo'
content_panels = [
AbstractHomePage.content_panels[0], # title
FieldPanel('extra'),
AbstractHomePage.content_panels[-1] # streamfield …Run Code Online (Sandbox Code Playgroud) 我得到:'
需要意外类型:变量
找到:值'在标记的行(*)
for (int i = 0; i < boardSize; i++) {
for (int j = 0; j < boardSize; j++) {
rows[i].getSquare(j) = matrix[i][j]; // * points to the ( in (j)
columns[j].getSquare(i) = matrix[i][j]; // * points to the ( in
int[] b = getBox(i, j);
int[] boxCord = getBoxCoordinates(i + 1, j + 1);
boxes[b[0]][b[1]].getSquare(boxCord[0], boxCord[1]);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的Row类:
private Square[] row;
Row(int rowCount) {
this.row = new Square[rowCount];
}
public Square getSquare(int index) {
return …Run Code Online (Sandbox Code Playgroud)