Ich habe ein Problem mit einem Blackjack -Spiel, der versucht, eine String -ArrayList in eine int -arrayList zu verwandeln, um es zusammen zu fügen, um ein int zu bilden.
public static void cardList() {
getFile();
try {
String cardValue = randomCard;
cardList.add(cardValue);
} catch (NumberFormatException e) {
System.err.println("Error");
}
for (String str : cardList) {
try {
cardTotalNum += Integer.parseInt(str);
} catch (NumberFormatException e) {
System.err.println("Invalid number format: " + str);
}
}
}
< /code>
Ich habe eine TXT -Datei, die alle Werte enthält (Gesichtskarten wurden in Zehns umgewandelt, Ace wurde auf 11 geworden). Wenn ich versuche, die Int ArrayList zu addieren, gibt es die falsche Nummer. Zum Beispiel, als ich es getestet habe, bekam ich 10 und 10 als meine Karten, und es kam mit 52. Jede Idee, warum das geschieht.
Quellcode: < /p>
import java.io.*;
import java.nio.file.*;
import java.util.*;
public class Main{
static String randomCard;
static ArrayList cardList = new ArrayList();
static boolean answer;
static boolean bust;
static ArrayList total = new ArrayList();
static int cardTotalNum = 0;
//Get Random Card
public static String getRandomLine(String filePath) throws IOException {
List lines = Files.readAllLines(Paths.get(filePath));
if (lines.isEmpty()) {
return null;
}
Random random = new Random();
int randomIndex = random.nextInt(lines.size());
return lines.get(randomIndex);
}
public static void getFile() {
String filePath = "Card.txt";
try {
randomCard = getRandomLine(filePath);
if (randomCard != null) {
System.out.println("");
} else {
System.out.println("The file is empty.");
}
} catch (IOException e) {
System.err.println("Error reading the file: " + e.getMessage());
}
}
public static void cardList() {
getFile();
try {
String cardValue = randomCard;
cardList.add(cardValue);
} catch (NumberFormatException e) {
System.err.println("Error");
}
for (String str : cardList) {
try {
cardTotalNum += Integer.parseInt(str);
} catch (NumberFormatException e) {
System.err.println("Invalid number format: " + str);
}
}
}
//Main run.
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int count = 2;
while (count > 1) {
//Starting Cards.
count = 2;
cardTotalNum = 0;
cardList.clear();
while (count < 4) {
cardList();
count++;
}
System.out.println("Starting cards are: " + cardList);
//Main game loop.
do {
System.out.println("Do you want to hit or stand? true(means hit). false(means stand).");
answer = scanner.nextBoolean();
if (answer = true) {
cardList();
} else if (answer = false) {
if (cardTotalNum == 21) {
System.out.println("Blackjack! You Win!");
}
}
if (cardTotalNum > 21) {
bust = true;
System.out.println("You busted");
System.out.println("Total was: " + cardTotalNum);
break;
}
System.out.println("Cards are: " + cardList);
System.out.println("Total is: " + cardTotalNum);
} while (answer != false || bust != true);
//End message.
System.out.println("Do you want to quit? 1 for yes. 0 for no.");
int endGameAns = scanner.nextInt();
if (endGameAns == 1) {
break;
} else if (endGameAns == 0) {
System.out.println("Thank you for staying.");
} else {
System.out.println("Invalid choice. I assume you want to end. If not next time make sure to put the number 0.");
break;
}
}
}
}
Ich habe ein [url=viewtopic.php?t=20324]Problem[/url] mit einem Blackjack -Spiel, der versucht, eine String -ArrayList in eine int -arrayList zu verwandeln, um es zusammen zu fügen, um ein int zu bilden.[code] public static void cardList() { getFile(); try { String cardValue = randomCard; cardList.add(cardValue); } catch (NumberFormatException e) { System.err.println("Error"); }
for (String str : cardList) { try { cardTotalNum += Integer.parseInt(str); } catch (NumberFormatException e) { System.err.println("Invalid number format: " + str); } } } < /code> Ich habe eine TXT -Datei, die alle Werte enthält (Gesichtskarten wurden in Zehns umgewandelt, Ace wurde auf 11 geworden). Wenn ich versuche, die Int ArrayList zu addieren, gibt es die falsche Nummer. Zum Beispiel, als ich es getestet habe, bekam ich 10 und 10 als meine Karten, und es kam mit 52. Jede Idee, warum das geschieht. Quellcode: < /p> import java.io.*; import java.nio.file.*; import java.util.*; public class Main{ static String randomCard; static ArrayList cardList = new ArrayList(); static boolean answer; static boolean bust; static ArrayList total = new ArrayList(); static int cardTotalNum = 0;
//Get Random Card public static String getRandomLine(String filePath) throws IOException { List lines = Files.readAllLines(Paths.get(filePath)); if (lines.isEmpty()) { return null; } Random random = new Random(); int randomIndex = random.nextInt(lines.size()); return lines.get(randomIndex); } public static void getFile() { String filePath = "Card.txt";
Ich versuche, einen sehr einfachen JUNIT -Test in das Spring Cloud -Projekt zu erstellen:
@SpringBootTest(classes = {ProductMapper.class })
public class TestingWebApplicationTests {
Ich versuche, einen konvexen Rumpfansatz durchzuführen, und das kleine Problem bestehtprivate void isConvexHull(Ponto[] points) {
Arrays.sort(points);
for (int i = 0; i
isClockWise(points ,points...