如何读取Android应用程序中的文本文件:
"1.something written
2.in this file
3.is to be read by
4.the InputStream
..."
Run Code Online (Sandbox Code Playgroud)
所以我可以返回一个字符串,如:
"something written\nin this file\nis to be read by\nthe InputStream"
Run Code Online (Sandbox Code Playgroud)
我想到的是(伪代码):
make an inputstream
is = getAssest().open("textfile.txt"); //in try and catch
for loop{
string = is.read() and if it equals "." (i.e. from 1., 2., 3. etc) add "/n" ...
}
Run Code Online (Sandbox Code Playgroud) 对于这个问题:
超级巨星是一个可以像女王一样移动的棋子,但也像骑士一样.8X8棋盘上的超级最大数量是多少,这样任何人都无法捕获另一个?
我想写一个强力算法来找到最大值.这是我写的:
public class Main {
public static boolean chess[][];
public static void main(String[] args) throws java.lang.Exception {
chess = new boolean[8][8];
chess[0][0] = true;
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
/*Loop to check various possibilities*/
if (!checkrow(i) && !checkcolumn(j) && !checkdiagonals(i, j) && !checkknight(i, j)) {
if (i != 0 || j != 0) {
chess[i][j] = true;
}
}
}
}/*printing the array*/ …Run Code Online (Sandbox Code Playgroud) 好吧,很可能它会被标记为重复,但我正在寻找答案,但找不到类似的东西.问题是:我想在特定范围内生成随机数[即min_value到max_value]并使用特定步骤.对于第一部分,答案是:
int random_value = rand() % max_value + min_value;
Run Code Online (Sandbox Code Playgroud)
该步骤如何定义它?我想上面提到的解决方案导致步骤1.正确吗?如果我想用步骤2(例如2,4,...,16)生成数字,我该怎么办?
我刚刚开始使用动画精灵并添加了一个,但它似乎无法正常工作,任何帮助都会受到赞赏.
它只是将精灵显示为黑盒子.背景显示了.我发现,如果我没有使用(bi~).load();它会显示为黑盒子,但它有一个load();.
01-07 10:47:48.049: W/System.err(2879): org.andengine.opengl.texture.atlas.buildable.builder.ITextureAtlasBuilder$TextureAtlasBuilderException: Could not build: 'AssetBitmapTextureAtlasSource(gfx/face_hexagon_tiled.png)' into: 'BitmapTextureAtlas'.
01-07 10:47:48.049: W/System.err(2879): at org.andengine.opengl.texture.atlas.buildable.builder.BlackPawnTextureAtlasBuilder.build(BlackPawnTextureAtlasBuilder.java:87)
01-07 10:47:48.049: W/System.err(2879): at org.andengine.opengl.texture.atlas.buildable.BuildableTextureAtlas.build(BuildableTextureAtlas.java:236)
01-07 10:47:48.059: W/System.err(2879): at com.example.pilet.Game.onCreateResources(Game.java:48)
01-07 10:47:48.059: W/System.err(2879): at org.andengine.ui.activity.BaseGameActivity.onCreateGame(BaseGameActivity.java:181)
01-07 10:47:48.059: W/System.err(2879): at org.andengine.ui.activity.BaseGameActivity.onSurfaceCreated(BaseGameActivity.java:110)
01-07 10:47:48.059: W/System.err(2879): at org.andengine.opengl.view.EngineRenderer.onSurfaceCreated(EngineRenderer.java:80)
01-07 10:47:48.059: W/System.err(2879): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1494)
01-07 10:47:48.059: W/System.err(2879): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
Run Code Online (Sandbox Code Playgroud)
private Camera mCamera;
private int c_width = 640;
private int c_height = 480;
private BuildableBitmapTextureAtlas mBitmapTextureAtlas;
private TiledTextureRegion pi;
private Scene mScene; …Run Code Online (Sandbox Code Playgroud) 我需要解决一个问题,当输入整数时,这是用户想要在此输入旁边输入的行数(一些句子),如文本所述,如下所示:
第一行输入包含一个整数N,表示输入中的行数.接下来是N行输入文本.
我写了以下代码:
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
String lines[] = new String[n];
for(int i = 0; i < n; i++){
System.out.println("Enter " + i + "th line");
lines[i] = scan.nextLine();
}
}
}
Run Code Online (Sandbox Code Playgroud)
并与该计划的互动:
5(The user inputted 5)
Enter 0th line(Program outputted this)
Enter 1th line(Doesn't gave time to input and instantly printed this message)
Hello(Gave time to write some input)
Enter 2th line(Program outputted this)
How(User input)
Enter …Run Code Online (Sandbox Code Playgroud)