在我的代码中创建搜索方法以搜索字符串时,我一直收到此错误.我已经经历了很多试图解决这个问题的例子,但我找不到.感谢您的帮助,并建议您给予.
public class runNote {
public static void main(String[] args) {
// TODO Auto-generated method stub
Notebook note = new Notebook();
note.storeNote("happy");
note.storeNote("hello there");
note.storeNote("work at 5");
note.storeNote("BBQ Time");
note.storeNote("UNI!!!!");
note.storeNote("Dont miss lecture at 9:15");
System.out.println(note.numberOfNotes());
note.showNote(1);
note.searchNotes("hap");
}}
public class Notebook{
/**
* Perform any initialization that is required for the
* notebook.
*/
public Notebook()
{
notes = new ArrayList();
}
/**
* Store a new note into the notebook.
* @param note The note to be stored. …Run Code Online (Sandbox Code Playgroud) 我一直在尝试编写一个isWhole给出double 的函数,看看它是否是整数,如果它返回没有小数的值(作为int?),否则返回3位小数(我可以这样做)数字格式的部分.
我的问题是如何检查double是一个整数还是一个递归小数?
我正在查看一段我没写过的Java代码,并注意到它在一些地方包含了&.它是一个从中缀到后缀符号转换器的代码.
如果我把这段代码放在Eclipse中它不喜欢这些&s并为它们创建错误,错误就是& cannot be resolved as a variable.
继承人的代码
public static String[] infixToRPN(String[] inputTokens) {
ArrayList<String> out = new ArrayList<String>();
Stack<String> stack = new Stack<String>();
// For all the input tokens [S1] read the next token [S2]
for (String token : inputTokens) {
if (isOperator(token)) {
// If token is an operator (x) [S3]
while (!stack.empty() && isOperator(stack.peek())) {
// [S4]
if ((isAssociative(token, LEFT_ASSOC) && cmpPrecedence(
token, stack.peek()) <= 0)
|| (isAssociative(token, RIGHT_ASSOC) && cmpPrecedence(
token, stack.peek()) < …Run Code Online (Sandbox Code Playgroud) 使用C++和OpenGL,我使用四边形,线条和点绘制了一个Cube.我现在正试图让我的代码更密集.为了达到这个目的,我想使用for循环.
我的立方体的顶点是二维数组,如下所示:
double vertices[8][3] = {
{ 1.0f, 1.0f, 1.0f}, //0
{ 1.0f, 1.0f,-1.0f}, //1
{ 1.0f,-1.0f,-1.0f}, //2
{-1.0f,-1.0f,-1.0f}, //3
{-1.0f,-1.0f, 1.0f}, //4
{-1.0f, 1.0f, 1.0f}, //5
{-1.0f, 1.0f,-1.0f}, //6
{ 1.0f,-1.0f, 1.0f} //7
};
Run Code Online (Sandbox Code Playgroud)
目前我用线条绘制立方体的代码是
void drawLines(){
glBegin(GL_LINES);
//Front Lines
//Left
glVertex3f(vertices[5][0],vertices[5][1],vertices[5][2]);
glVertex3f(vertices[4][0],vertices[4][1],vertices[4][2]);
//Top
glVertex3f(vertices[5][0],vertices[5][1],vertices[5][2]);
glVertex3f(vertices[0][0],vertices[0][1],vertices[0][2]);
//Bottom
glVertex3f(vertices[4][0],vertices[4][1],vertices[4][2]);
glVertex3f(vertices[7][0],vertices[7][1],vertices[7][2]);
//Right
glVertex3f(vertices[7][0],vertices[7][1],vertices[7][2]);
glVertex3f(vertices[0][0],vertices[0][1],vertices[0][2]);
//Middle Lines
//Top Left
glVertex3f(vertices[6][0],vertices[6][1],vertices[6][2]);
glVertex3f(vertices[5][0],vertices[5][1],vertices[5][2]);
//Top Right
glVertex3f(vertices[1][0],vertices[1][1],vertices[1][2]);
glVertex3f(vertices[0][0],vertices[0][1],vertices[0][2]);
//Bottom Left
glVertex3f(vertices[3][0],vertices[3][1],vertices[3][2]);
glVertex3f(vertices[4][0],vertices[4][1],vertices[4][2]);
//Bottom Right
glVertex3f(vertices[2][0],vertices[2][1],vertices[2][2]);
glVertex3f(vertices[7][0],vertices[7][1],vertices[7][2]);
//Back Lines
//Left
glVertex3f(vertices[6][0],vertices[6][1],vertices[6][2]);
glVertex3f(vertices[3][0],vertices[3][1],vertices[3][2]);
//Top
glVertex3f(vertices[6][0],vertices[6][1],vertices[6][2]);
glVertex3f(vertices[1][0],vertices[1][1],vertices[1][2]);
//Bottom …Run Code Online (Sandbox Code Playgroud) 最近开始使用Haskell,我遇到了几个基本问题.
我写了一个简单的程序来对一个名为'square'的变量进行平方.现在我正在尝试编写一个名为pyth的程序,它接受3个变量将它们全部输入正方形,然后将平方加到b平方以查看它是否等于c平方以确定它们是否形成毕达哥拉斯三元组.
square :: Int -> Int
square x = x*x
pyth :: Int -> Int -> Int -> Bool
pyth a b c
a = square a
b = square b
c = square c
a+b == c = True
Run Code Online (Sandbox Code Playgroud) 我正在用Java制作一个地下城游戏.我创建了一个将地图存储在2D数组中的方法.该数组如下所示:
[[#, #, #, #, #, #, #, #, #, #, #, #, #, #, #, #, #, #, #],
[#, ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., #],
[#, ., ., ., ., ., ., G, ., ., ., ., ., ., ., ., E, ., #],
[#, ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., #],
[#, ., ., …Run Code Online (Sandbox Code Playgroud) java printing arrays multidimensional-array indexoutofboundsexception