• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to check if a 2d array contains all digits  RSS feed

 
Taylor Shell
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my code so far. How can I fix it. Error: unenclosed string literal

 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Is matrix declared as a String[]? If not, then you're comparing non-Strings with Strings because you put quotes around those numbers. If matrix is an array of numbers then just remove the quotes around the numbers you're trying to compare.
 
Taylor Shell
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting an error for unenclosed literal and I don't know how to fix it and matrix is declared as an int
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like I said, remove the quotes around 47 and 58. Numeric literal values should not be quoted. Single quotes are for char literals. Double quotes are for String literals.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Taylor Shell wrote:This is my code so far. How can I fix it. Error: unenclosed string literal

I'm not quite sure what this has to do with "2d array"s.

From what I can see, your code is doing the same check, on the same 1d array, with two different indexes - which I suspect is NOT what you want.

Why don't you show us all your relevant code and explain what you're trying to do. Then we'll be able to advise you better.

Winston
 
Liutauras Vilda
Sheriff
Posts: 4928
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Taylor Shell
Wikipedia wrote:In mathematics, a matrix (plural matrices) is a rectangular array...
Since you call it matrix.. Your both loops iterates to the same length 10, that suggests without seeing the rest of the code that most likely it is not correct, unless your matrix is a square matrix, but then call it squareMatrix to disambiguate it.

Never use magic numbers (especially when you're working with arrays of arrays, you'll understand it soon "why"), 10 says nothing to your code reader. Try to use matrix.length or squareMatrix.length.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liutauras Vilda wrote:. . .. use matrix.length or squareMatrix.length.
In an array of arrays, you can use
matrix[i].length
because that value can vary from array to array; that is often called a jagged array. As Liutauras has said, a matrix has all its rows the same length and that is often called a rectangular array.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!