所以我试着让我们说int Posx;保持一个数字,然后当用户浏览菜单时,根据他们选择的内容,将添加1,0或-1 int Posx.Posx添加或减去后我无法保留数字.我正在尝试浏览数组,我想保留2个整数作为标记,让我知道我目前在数组中的x和y.
tl; dr如何在do/while循环中保留一个计数器?
这是问题所在:
//this variable will hold if we found or not the string in the puzzle
boolean found = true;
do {
//Print out the array
for (int x = 0; x < maze.length; x++) {
for (int y = 0; y < maze[0].length; y++) {
System.out.print(maze[x][y]);
}
System.out.println();
}
System.out.printf("You may:\n1) Move up\n2) Move down\n3) Move left\n4) Move right\n0) Quit\nYour Choice (0-4):\n");
int usrAns = sc2.nextInt();
if (usrAns == …Run Code Online (Sandbox Code Playgroud) 让我们说我有字符串:'救火车'.然后我将该字符串分成单个字母并将它们放入一个名为T的数组中.所以现在T []看起来像{f,i,r,e,t,r,u,c,k}.我如何才能打印偶数个字符,所以我的print语句看起来像"frtuk"和奇看起来像"IERC".这是我到目前为止所得到的:
import java.util.Scanner;
import java.util.Arrays;
public class StringFun {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String even_odd = sc.next();
char[] t = even_odd.toCharArray();
System.out.println(Arrays.toString(t));
//I can't get this next part to work.
for(int i = t[0]; i < t.length; i = i + 2){
System.out.println(Arrays.toString(t[i]));
}
}
}
Run Code Online (Sandbox Code Playgroud) 让我说我有一个char数组迷宫[] []它包含这个:
P . X X .
. X . . .
. . . X .
X X T . .
. . X . .
Run Code Online (Sandbox Code Playgroud)
我正在编写一个函数,如果你想向下移动,将迷宫[0] [0]中的"P"带到迷宫[1] [0],然后带"." 从迷宫[1] [0]到迷宫[0] [0]等等......
基本上我如何交换char数组中2个索引的值?
好的,所以我正在尝试编写一个我在汽车上竞标的程序.我想要做的是,如果当前出价为零,那么最低出价是起始出价.如果当前出价不为零,则最低出价是当前出价加上最低出价.我不断收到错误消息incompatible types when assigning to type 'float[5]' from type 'float'.
这是我的代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int menu1();
int main()
{
FILE * ifp = fopen("input2.txt","r"); //Open the input file
int cars = 5, i , j, k; // Initialized cars and counters i, j, and k
char *VIEW="VIEW", *BID="BID", *CLOSE="CLOSE", choice1[20]; //Initialize character arrays
float CAR[5]={1,2,3,4,5},START_BID[5]={0.00}, MIN_BID[5]={0.00}, CUR_BID[5]={0.00}, USR_BID[5]={0.00}; //Initialized float arrays
int compareLimit = 100, selection=0;
//Scan the file and appropriate the numbers into their …Run Code Online (Sandbox Code Playgroud)