Why do Min & Max show up as 0 in my array? - java

Why do Min & Max show up as 0 in this array?
I tried to figure it out for a while now but I couldn't wrap my head around it.
public class Main
{
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int n=input.nextInt();
int []x=new int[n-1];
random(x);
sizeArray(x);
System.out.println("The min is "+ min(x));
System.out.println("The max is "+ max(x));
System.out.println("The Total is "+ getTotal(x));
}
public static int random(int[]x){
Random rand=new Random();
for (int i = 0; i < x.length; i++) {
x[i]=rand.nextInt(101);
}
return 0;
}
public static int sizeArray(int []x){
for (int i = 0; i < x.length; i++) {
System.out.println(x[i]);
}
return 0;
}
Here is the 'min'.
public static int min(int[]x){
int min=0;
for (int i = 0; i < x.length; i++) {
if(x[i]<min){
min=x[i];
}
}
return min;
}
And the 'max' I am not sure what the issue is.
public static int max(int[]x){
int max=0;
for (int i = 0; i < x.length; i++) {
if(x[i]>max)
x[i]=max;
i++;
}
return max;
}
public static int getTotal(int[]x){
int total=0;
for (int i = 0; i < x.length; i++) {
total=total+x[i];
}
return total;
}
}```
||SOLVED||
Changed min and max and also added maximum(x); minimum(x); in main while removing ^^ System.out.println("The min is "+ min(x)); ^^
^^ System.out.println("The max is "+ max(x));.^^
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int n=input.nextInt();
int []x=new int[n];
random(x);
sizeArray(x);
maximum(x);
minimum(x);
System.out.println("The Total is "+ getTotal(x));
}
public static int random(int[]x){
Random rand=new Random();
for (int i = 0; i < x.length; i++) {
x[i]=rand.nextInt(101);
}
return 0;
}
public static int sizeArray(int []x){
for (int i = 0; i < x.length; i++) {
System.out.println(x[i]);
}
return 0;
}
|Changed max|
public static void maximum(int x[]) {
int max = x[0];
for (int i = 1; i < x.length; i++) {
if (x[i] > max) {
max = x[i];
}
}
System.out.println("maximum is:" + max);
}
|And changed min|
public static void minimum(int x[]) {
int min = x[0];
for (int i = 1; i < x.length; i++) {
if (x[i] < min) {
min = x[i];
}
}
System.out.println("minimum is:" + min);
}
public static int getTotal(int[]x){
int total=0;
for (int i = 0; i < x.length; i++) {
total=total+x[i];
}
return total;
}
}

Here you are probably setting every element in the array to 0. And in any case, max is always going to return 0
public static int max(int[]x){
int max=0;
for (int i = 0; i < x.length; i++) {
if(x[i]>max)
x[i]=max;
i++;
}
return max;
}
And here, you are starting with min = 0 (which isn't necessarily a value in the array) and since all the values are greater than 0, the return value is 0.
public static int min(int[]x){
int min=0;
for (int i = 0; i < x.length; i++) {
if(x[i]<min){
min=x[i];
}
}
return min;
}
And honestly, it would have been very easy or you to figure this out if you'd used the debugger to step through your functions. Learning how to use a debugger is an invaluable skill!

Related

What changes are to be made to run this code?

package com.company;
import java.util.*;
public class Main {
public static int Largest(int array[]) {
int largest = Integer.MIN_VALUE;
for (int i = 0; i <= 5; i++) {
if (array[i] > largest) {
array[i] = largest;
}
System.out.println(largest);
}
return largest;
}
public static void main(String[] args) {
// write your code here
Scanner sc = new Scanner(System.in);
int array[] = new int[5];
for (int i = 0; i <= 5; i++) {
array[i] = sc.nextInt();
System.out.println(array[i]);
}
Largest(array);
System.out.println("largest element is : "+Largest(array));
}
}
This is the code to find the largest no. in an array but the output I'm getting for this code isn't desirable. Please check and let me know the problems in this code.
public static int Largest(int array[]) {
int largest = Integer.MIN_VALUE;
//for (int i = 0; i <= 5; i++) {
//wrong loop range
for (int i = 0; i < array.length; i++) {
if (array[i] > largest) {
//array[i] = largest;
//wrong assignment
largest = array[i];
}
System.out.println(largest);
}
return largest;
}
Try like this :
package com.company;
import java.util.*;
public class Main {
public static int Largest(int array[]) {
int largest = Integer.MIN_VALUE;
for (int i = 0; i < 5; i++) {
if (array[i] > largest) {
largest = array[i];
}
System.out.println(largest);
}
return largest;
}
public static void main(String[] args) {
// write your code here
Scanner sc = new Scanner(System.in);
int array[] = new int[5];
for (int i = 0; i < 5; i++) {
array[i] = sc.nextInt();
System.out.println(array[i]);
}
Largest(array);
System.out.println("largest element is : "+Largest(array));
}
}
You are wrong on two thing :
the loops on your array go until index = 5, however your array has a length of 5, so the last index is 4.
you were assigning array[i] = largest instead of largest = array[i]

I am attempting to create a class that will display info about a set of integers, but I cannot call my class

OK, I attempted to understand your answers and have changed my code, but I am still running into similar problems. I am attempting to call the IntArray constructor into my IntMath constructor, as there are variables I need to get my math to work. After which, I am attempting to call both constructors into my Main class. However, it is telling my that all my variables "might not have been initialized.
I am so very new at this and just feel dumb and helpless. And I have used Google like crazy.
Thank you in advance for your help.
package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
//int sum, even, odd, min, max, size;
//int [] intArray;
//double average;
//int even = 0, odd = 0, min = 0, max = 0, size = 0, sum = 0;
//double average;
System.out.print("Please enter a number for the array size (zero or greater): ");
int n=in.nextInt();
if (n<0){
System.out.println("ERROR: Number must be at least zero!!!");
}else {
IntArray mainArray = new IntArray(n);
}
//com.company.IntMath intMath = new com.company.IntMath(average, even, odd, min, max, size, sum);
IntMath intMath = new IntMath();
//intMath.getAverage();
intMath.getEven();
intMath.getOdd();
intMath.getMin();
// intMath.getMax();
intMath.getSize();
intMath.getSum();
System.out.println("Average: " + intMath.getAverage() ); //print the average of the elements
System.out.println("Even Count: " + intMath.getEven()); //prints the count of all even numbers
System.out.println("Odd Count: " + intMath.getOdd()); //prints the count of all odd numbers
System.out.println("Min: " + intMath.getMin()); //prints the min number
//System.out.println("Max: " + intMath.getMax()); //prints the max number
System.out.println("Size: " + intMath.getSize()); //prints the size of the array
System.out.println("Sum: " + intMath.getSum()); //prints the sum of all elements
}
}
package com.company;
import java.util.Arrays;
import java.util.Random;
public class IntArray {
private int n;
private int [] intArray;
private double average;
private int sum;
private int even;
private int odd;
private int max;
private int min;
private int size;
public IntArray(int n) {
this.n = n;
Random randArray = new Random();
int[] intArray = new int[n];
intArray[0] = 0; //why does this not make the element 0 a 0?????????
for (int i = 0; i < n; i++) {
intArray[i] = randArray.nextInt(50); //I was getting very big random numbers, so I set the max to 50
}
System.out.println("Set: " + Arrays.toString(intArray));
}
public double getAverage() {
average = 0;
double total = 0;
for (int i = 0; i < n; i++) {
total = total + intArray[i];
}
return average;
}
public int getSum() {
//find the sum of all elements
sum = 0;
for (int i = 0; i < n; i++) {
sum += intArray[i];
}
return sum;
}
public int getEven() {
even = 0;
for (int i = 0; i < n; i++) {
if (intArray[i] % 2 == 0) {
even++;
}
}
return even;
}
public int getOdd() {
odd = 0;
for (int i = 0; i < n; i++) {
if (intArray[i] % 2 != 0) {
odd++;
}
}
return odd;
}
public int getMax() {
max = intArray[0];
for (int i = 1; i < n; i++) {
if (intArray[i] > max) {
max = intArray[i];
}
}
return max;
}
public int getMin() {
min = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < intArray.length; j++) {
if (intArray[i] > intArray[j]) {
min = intArray[i];
intArray[i] = intArray[j];
intArray[j] = min;
}
}
}
return min;
}
public int getSize() {
//find the size of the array
size = n + 1;
return size;
}
}
package com.company;
public class IntMath {
private double average;
private int sum;
private int even;
private int odd;
private int max;
private int min;
private int size;
private int[] intArray;
private int n;
//com.company.IntArray mainArray = new com.company.IntArray(n); //call IntArray to get variables ''n'' and ''intArray''
/*public IntMath(double average, int sum, int even, int odd, int max, int min, int size, int[] intArray) {
this.average = average;
this.sum = sum;
this.even = even;
this.odd = odd;
this.max = max;
this.min = min;
this.size = size;
this.intArray = intArray;
com.company.IntArray mainArray = new com.company.IntArray(n); //call IntArray to get variables ''n'' and ''intArray''
// average = 0;
// double total = 0;
// for (int i = 0; i < n; i++) {
// total = total + intArray[i];
// }
//find the sum of all elements
//sum = 0;
//for (int i = 0; i < n; i++) {
// sum += intArray[i];
//}
//find the count of the even numbers
//even = 0;
//for (int i = 0; i < n; i++) {
// if (intArray[i] % 2 == 0) {
// even++;
// }
//}
//find the count of the odd numbers
//odd = 0;
//for (int i = 0; i < n; i++) {
// if (intArray[i] % 2 != 0) {
// odd++;
// }
//}
//find the biggest number
//max = intArray[0];
//for (int i = 1; i < n; i++) {
// if (intArray[i] > max) {
// max = intArray[i];
// }
//}
//find the smallest number
//min = 0;
//for (int i = 0; i < n; i++) {
// for (int j = i + 1; j < intArray.length; j++) {
// if (intArray[i] > intArray[j]) {
// min = intArray[i];
// intArray[i] = intArray[j];
// intArray[j] = min;
// }
// }
/
//find the size of the array
//size = n + 1;
*/
public double getAverage() {
average = 0;
double total = 0;
for (int i = 0; i < n; i++) {
total = total + intArray[i];
}
return average;
}
public int getSum() {
//find the sum of all elements
sum = 0;
for (int i = 0; i < n; i++) {
sum += intArray[i];
}
return sum;
}
public int getEven() {
even = 0;
for (int i = 0; i < n; i++) {
if (intArray[i] % 2 == 0) {
even++;
}
}
return even;
}
public int getOdd() {
odd = 0;
for (int i = 0; i < n; i++) {
if (intArray[i] % 2 != 0) {
odd++;
}
}
return odd;
}
public int getMax() {
max = intArray[0];
for (int i = 1; i < n; i++) {
if (intArray[i] > max) {
max = intArray[i];
}
}
return max;
}
public int getMin() {
min = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < intArray.length; j++) {
if (intArray[i] > intArray[j]) {
min = intArray[i];
intArray[i] = intArray[j];
intArray[j] = min;
}
}
}
return min;
}
public int getSize() {
//find the size of the array
size = n + 1;
return size;
}
}
In class Main, if you initialize all the variables, that class will compile without errors.
By going through your classes, I think what you might want to do is,
Accept a number to create an array of that size and populate the array with some random numbers
Next you want to perform various operations like finding average, sum, etc by using the array that you have populated.
If this is the case, then you would have to do something like this...
Effectively, you need not have the IntArray class.
Declare int[] intArray as a class level variable in IntMath class and populate that array as you are doing it now, in the constructor of IntArray class.
define multiple methods in your IntMath class for each of the operations..average, sum, etc and call them in the Main class while you are printing the answer.
You will have to correct the code in getAverage, getSize and getMin methods.

I cannot get my methods math to work in my main class in my java program

I am attempting some array work for school. I am getting a user input for the size of the array, which will be filled with random elements. After I need to do some simple math; how many odd numbers, even numbers, sum of all etc. I have wrote everything, however the methods I wrote for the maths, does not compute to my main program, I am just getting "0"s for everything.
Excuse all of the comments, as you can probably tell, I have been trying multiple things.
package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
//int sum, even, odd, min, max, size;
//int [] intArray;
//double average;
//int even = 0, odd = 0, min = 0, max = 0, size = 0, sum = 0;
//double average;
System.out.print("Please enter a number for the array size (zero or greater): ");
int n=in.nextInt();
if (n<0){
System.out.println("ERROR: Number must be at least zero!!!");
}else {
IntArray mainArray = new IntArray(n);
}
//com.company.IntMath intMath = new com.company.IntMath(average, even, odd, min, max, size, sum);
IntArray.IntMath intMath = new IntArray.IntMath();
//intMath.average();
//intMath.even();
//intMath.getOdd();
//intMath.getMin();
//intMath.getMax();
//intMath.getSize();
//intMath.getSum();
System.out.println("Average: " + intMath.average()); //print the average of the elements
System.out.println("Even Count: " + intMath.even()); //prints the count of all even numbers
System.out.println("Odd Count: " + intMath.odd()); //prints the count of all odd numbers
System.out.println("Min: " + intMath.min()); //prints the min number
System.out.println("Max: " + intMath.max()); //prints the max number
System.out.println("Size: " + n); //prints the size of the array
System.out.println("Sum: " + intMath.sum()); //prints the sum of all elements
}
}
package com.company;
import java.util.Arrays;
import java.util.Random;
public class IntArray {
private int[] intArray;
public IntArray(int n) {
Random randArray = new Random();
int[] intArray = new int[n];
intArray[0] = 0; //why does this not make the element 0 a 0?????????
for (int i = 0; i < n; i++) {
intArray[i] = randArray.nextInt(50); //I was getting very big random numbers, so I set the max to 50
}
System.out.println("Set: " + Arrays.toString(intArray));
}
public static class IntMath {
double average;
int sum;
int even;
int odd;
int max;
int min;
int size;
int[] intArray;
int n;
//public IntMath() {//making a new constructor!!!!!!!!!!!!!!!!!!!!!!!
// this.average=average;
// this.sum=sum;
// this.even=even;
// this.odd=odd;
// this.max=max;
// this.min=min;
// this.size=size;
public double average () {
average = 0;
double total = 0;
for (int i = 0; i < n; i++) {
total = total + intArray[i];
}
return average;
}
// n should equal array length??????????
public int sum() {
//find the sum of all elements
sum = 0;
for (int i = 0; i < n; i++) {
sum += intArray[i];
}
return sum;
}
public int even() {
even = 0;
for (int i = 0; i < n; i++) {
if (intArray[i] % 2 == 0) {
even++;
}
}
return even;
}
public int odd() {
//odd = 0;
for (int i = 0; i < n; i++) {
if (intArray[i] % 2 != 0) {
this.odd++;
}
}
return odd;
}
public int max() {
max = intArray[0];
for (int i = 1; i < n; i++) {
if (intArray[i] > max) {
max = intArray[i];
}
}
return max;
}
public int min() {
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < intArray.length; j++) {
if (intArray[i] > intArray[j]) {
min = intArray[i];
intArray[i] = intArray[j];
intArray[j] = min;
}
}
}
return min;
}
public int size() {
size = n;
return size;
}
}
}
Seems like you are struggling with certain concepts so I would suggest you to look at this code and compare it with what you wrote to determine where things went wrong.
Main.java
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
IntArray mainArray = null;
System.out.print("Please enter a number for the array size (zero or greater): ");
int size = in.nextInt();
if (size < 0) {
System.err.println("ERROR: Number must be at least zero!!!");
} else {
mainArray = new IntArray(size);
IntArray.IntMath intMath = new IntArray.IntMath(mainArray.getIntArray());
System.out.println("Average: " + intMath.average()); //print the average of the elements
System.out.println("Even Count: " + intMath.even()); //prints the count of all even numbers
System.out.println("Odd Count: " + intMath.odd()); //prints the count of all odd numbers
System.out.println("Min: " + intMath.min()); //prints the min number
System.out.println("Max: " + intMath.max()); //prints the max number
System.out.println("Size: " + intMath.size()); //prints the size of the array
System.out.println("Sum: " + intMath.sum()); //prints the sum of all elements
}
in.close();
}
}
IntArray.java
import java.util.Arrays;
import java.util.Random;
public class IntArray {
private int[] intArray;
public IntArray(int size) {
Random randArray = new Random();
intArray = new int[size];
intArray[0] = 0;
for (int i = 0; i < size; i++) {
intArray[i] = randArray.nextInt(50);
}
System.out.println("Outer Array: " + Arrays.toString(intArray));
}
public int[] getIntArray() {
return intArray;
}
public static class IntMath {
double average;
int sum;
int even;
int odd;
int max;
int min;
int size;
int[] intArray;
public IntMath(int[] intArray) {
this.intArray = intArray;
}
public double average() {
average = 0;
double total = 0;
for (int i = 0; i < intArray.length; i++) {
total += intArray[i];
}
average = total / intArray.length;
return average;
}
public int sum() {
sum = 0;
for (int i = 0; i < intArray.length; i++) {
sum += intArray[i];
}
return sum;
}
public int even() {
even = 0;
for (int i = 0; i < intArray.length; i++) {
if (intArray[i] % 2 == 0) {
even++;
}
}
return even;
}
public int odd() {
for (int i = 0; i < intArray.length; i++) {
if (intArray[i] % 2 != 0) {
this.odd++;
}
}
return odd;
}
public int max() {
max = intArray[0];
for (int i = 1; i < intArray.length; i++) {
if (intArray[i] > max) {
max = intArray[i];
}
}
return max;
}
public int min() {
min = intArray[0];
for(int i = 1; i < intArray.length; i++){
if(intArray[i] < min){
min = intArray[i];
}
}
return min;
}
public int size() {
size = intArray.length;
return size;
}
}
}
Output
Please enter a number for the array size (zero or greater): 5
Set: [0, 45, 10, 20, 45]
Average: 24.0
Even Count: 3
Odd Count: 2
Min: 0
Max: 45
Size: 5
Sum: 120
Do accept this answer if it solves your problem.

Name sorter returns -1?

Wrote name sorting program designed to sort a list of names (duh) and give index value of my name. It should return 1219 or so as my name is near last on the list, yet instead returns -1? What's wrong with my linearSearch method?
import java.io.*;
import java.util.Scanner;
public class NameSorter
{
public static void main(String [] args) throws FileNotFoundException
{
String [] maleNames = new String[1220];
PrintStream ps = new PrintStream("sorted_male_names.txt");
Scanner nameScan = new Scanner(new File("common_male_names.txt"));
for (int i = 0; i < maleNames.length; i++)
{
maleNames[i] = nameScan.nextLine();
}
bubbleSort(maleNames);
for (int i = 0; i < maleNames.length; i++)
{
System.out.println(maleNames[i]);
}
for (int i = 0; i < maleNames.length; i++)
{
String currentName = maleNames[i];
ps.println(currentName);
}
System.out.println(linearSearch(maleNames, "zander"));
}
public static boolean isSorted(String[] arr)
{
for (int i = 0; i < arr.length -1; i++)
{
if (arr[i].compareTo(arr[i+1]) > 0)
return false;
}
return true;
}
public static void swapElements(String[] arr, int index1, int index2)
{
String tempValue = arr[index1];
arr[index1] = arr[index2];
arr[index2] = tempValue;
}
public static void bubbleSort(String[] arr)
{
while(isSorted(arr) == false) // while(!isSorted(arr))
{
for (int i = 0; i < arr.length - 1; i++)
{
if (arr[i].compareTo(arr[i+1]) > 0)
swapElements(arr, i, i+1);
}
}
}
public static int linearSearch(String[] arr, String name)
{
for (int i = 0; i > arr.length; i++)
{
if (arr[i].equals(name))
return i;
}
return -1;
}
public static void printArray(int[] arr)
{
for (int i = 0; i < arr.length; i++)
{
System.out.print(arr[i] + " ");
}
}
}
Thanks in advance!
Change
for (int i = 0; i > arr.length; i++)
to
for (int i = 0; i < arr.length; i++)

How to change an array of ints to an array of strings?

Ok, the title might be deceiving. All i want to do is take my Bingo program and when the second bingo card is printed, i want to replace all the "0"'s with "X"'s. I was thinking i would have to go and change the array to an string, but i'm not surer where to start.
Here is the Bingo program:
import java.util.*;
import java.io.*;
import java.util.Arrays;
public class Bingo
{
public static final int ROWS = 5;
public static final int COLS = 5;
public static final int VERTICAL = 1;
public static final int DIAGONAL = 2;
public static final int HORIZONTAL = 3;
public static int winFound;
public static int currPick = 0;
public static int randomPick = 0;
public static int WinFound;
public static void main(String[] args)
{
int Totcards;
int[][] card = new int[ROWS][COLS];
int[] picks = new int[25];
fillCard (card);
printCard(card);
playGame(card);
printCard(card);
finalCard(card);
}
private static void fillCard (int[][] card)
{
// FileReader fileIn = new FileReader("Bingo.in");
// Bufferreader in = new Bufferreader(fileIn);
try {
Scanner scan = new Scanner(new File("bingo.in"));
for (int i=0; i<card.length; i++){
for (int j=0; j<card[0].length; j++){
card[i][j] = scan.nextInt();
}
}
} catch(FileNotFoundException fnfe) {
System.out.println(fnfe.getMessage());
}
}
private static void printCard (int[][] card)
{
System.out.println("\n\tYOUR BINGO CARD : ");
System.out.println("\n\tB I N G O");
System.out.println("\t----------------------");
for (int i=0; i<card.length; i++){
for (int j=0; j<card[0].length; j++){
System.out.print("\t" + card[i][j]);
}
System.out.print("\n");
}
}
private static void playGame (int[][] card)
{
int numPicks = 0;
System.out.println("\n\tBINGO NUMBERS PICKED AT RANDOM FROM BIN: ");
while (true)
{
markCard (card); // Generate a random num & zero-it out
winFound = checkForWin(card); // Look for zero sums
numPicks++;
if (winFound != 0)
{
if (winFound == 1)
{
System.out.print("\n\n\tYOU WIN WITH A VERTICAL WIN AFTER " + numPicks + " PICKS\n");
}
else if (winFound == 2){
System.out.print("\n\n\tYOU WIN WITH A DIAGONAL WIN AFTER " + numPicks + " PICKS\n");
}
else if (winFound == 3){
System.out.print("\n\n\tYOU WIN WITH A HORIZONTAL WIN AFTER " + numPicks + " PICKS\n");
}
announceWin (numPicks);
return;
}
}
}
private static void markCard (int[][] card)
{
int randomPick = (int) (Math.random() * 74) + 1;
for (int j = 0; j < ROWS; j++){
for (int k = 0; k < COLS; k++){
if (card[j][k]==randomPick)
card[j][k] = 0;}
}
System.out.print("\t " + randomPick + " ");
System.out.print("");
}
private static int checkForWin(int[][] card)
{
int sum=0;
for (int i = 0; i < ROWS; i++)
{
sum = 0;
for (int j = 0; j < COLS; j++)
sum += card[i][j];
if (sum == 0)
return HORIZONTAL;
}
for (int j = 0; j < COLS; j++)
{
sum = 0;
for (int i = 0; i < ROWS; i++)
sum += card[i][j];
if (sum == 0)
return VERTICAL;
}
sum = 0;
for (int i = 0; i < ROWS; i++)
sum += card[i][ROWS-i-1];
if (sum == 0)
return DIAGONAL;
sum = 0;
for (int i = 0; i < ROWS; i++)
sum += card[i][i];
if (sum == 0)
return DIAGONAL;
return WinFound;
}
private static void makeCard(int[][] card, int[] picks)
{
int count = 100;
int currPick = 0;
for (int i=0; i<count; i++){
currPick = (int)(Math.random() * 74) + 1;
System.out.print(" " + currPick + "\n");
picks[i] = currPick;
}
}
private static void announceWin(int numPicks)
{
}
private static boolean duplicate (int currPick, int[] picks, int numPicks)
{
for (int i = 0; i < numPicks; i++){
if (picks[i] == currPick){
return true;}
}
return false;
}
private static void finalCard (int[][] card)
{
Arrays.sort(card);
final String stringRep = Arrays.toString(card);
final String[] out =
stringRep.substring(1, stringRep.length() - 1).split("\\s*,\\s*");
System.out.println(Arrays.toString(out));
}
}
Try this:
System.out.print("\t" + (card[i][j] == 0 ? "X" : card[i][j]))
Why don't you just use a String[][] for the fields from the beginning? You can still compare String values with ints (with Integer.valueOf for instance) and this way you don't have to switch types runtime...

Categories

Resources