Results 1 to 5 of 5
Thread: String[][] - How to
- 12-04-2012, 06:01 PM #1
Member
- Join Date
- Dec 2012
- Posts
- 2
- Rep Power
- 0
-
Re: String[][] - How to
If this were my assignment, I'd simplify it first and figure out how to solve this with a 1 dimensional array. Once done it wouldn't be hard to extend that solution to a 2D array.
- 12-04-2012, 07:07 PM #3
Re: String[][] - How to
Why do they call it rush hour when nothing moves? - Robin Williams
- 12-05-2012, 12:23 PM #4
Member
- Join Date
- Dec 2012
- Posts
- 2
- Rep Power
- 0
Re: String[][] - How to
I tried every solution I found on internet but I'm always receiving this error: EXPECTED Array, FOUND String[][].
Java Code:import java.util.*; import java.io.*; public class Diagrama{ public static void main (String[] args) { int row, column; OnlyUpperCase alfa = new OnlyUpperCase(); // boolean classes with corresponding procedures OneCharOnly beta = new OneCharOnly(); // I am not writing them here because OnlyNumbers gama = new OnlyNumbers(); // it's easy to figure out what they perform. String matrix[][] = new String[13][20]; String wordToBeFound[]; String a, b; Scanner scan = new Scanner(System.in); System.out.println ("Only UPPER-CASE characters:"); for (row=0; row < 13; row++ ) for (column=0; column < 20; column++) { System.out.println ("Element " + row + " " + column); a=scan.nextLine(); while (!alfa.containsOnlyUpperCase (a) || !beta.containsOnlyOneChar (a)){ System.out.println ("One char only!"); a=scan.nextLine(); } matrix[row][column]=a; } for (row=0; row < 13; row++ ) { System.out.println (""); for (column=0; column < 20; column++) System.out.print (" " + matrix[row][column]); } System.out.println ("Word length (MIN 3, MAX 20):"); b=scan.nextLine(); while (!gama.containsOnlyNumbers (b) || Integer.parseInt( b )>20 || Integer.parseInt( b )<3){ System.out.println ("Erorr! Number of letters between 3 and 20!"); b=scan.nextLine(); } wordToBeFound=new String[Integer.parseInt( b )]; System.out.println ("One UPPER-CASE char at a time:"); for (row=0; row < wordToBeFound.length; row++ ){ System.out.println (row+1 + " letter: "); // It start default with 0 but I want to start with 1 a=scan.nextLine(); while (!alfa.containsOnlyUpperCase (a) || !beta.containsOnlyOneChar (a)){ System.out.println ("Only single UPPER-CASE chars allowed!"); a=scan.nextLine(); } wordToBeFound[row]=a; } } }
I know it's a mess. Have a bit of mercy for me! ^_^
So ... I want to find wordToBeFound in matrix.Last edited by eddierwalker; 12-05-2012 at 04:57 PM.
- 12-05-2012, 12:52 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: String[][] - How to
When you get an error you need to post the full description and highlight the location in your code it occurs on.
And you do need to sort out indenting your code properly.
It will help you immensely in that you can actually follow the flow of the code just by looking at it.Please do not ask for code as refusal often offends.
Similar Threads
-
Help String Error :[Ljava.lang.String;@121b26b6
By mathgram8 in forum New To JavaReplies: 1Last Post: 09-13-2012, 06:59 PM -
Dealing with floating-point in double and String and convert it to String
By emad7105 in forum New To JavaReplies: 3Last Post: 02-10-2012, 06:26 PM -
Basic string problem, just need to extract two numbers out of string
By gonzoateafly in forum New To JavaReplies: 6Last Post: 12-06-2010, 09:26 AM -
Binary-algorithm -> Insert String to sorted String-ArrayList
By Muskar in forum Advanced JavaReplies: 12Last Post: 11-26-2010, 08:33 AM -
Test for all empty Strings in LinkedHashMap<String,ArrayList<String>
By albertkao in forum New To JavaReplies: 1Last Post: 11-04-2010, 06:53 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks