You are viewing our Forum Archives. To view or take place in current topics click here.
Jave Array Problems - Need Help - Thanks!
Posted:

Jave Array Problems - Need Help - Thanks!Posted:

yoseaweed
  • Prospect
Status: Offline
Joined: Aug 04, 201014Year Member
Posts: 608
Reputation Power: 25
Status: Offline
Joined: Aug 04, 201014Year Member
Posts: 608
Reputation Power: 25
Hi. So I have some programs that need to be completed in java, and would appriate it if someone could help me. Thanks!!!

1. Write a value - returning method the returns the number of rows in a two - dimensional array of doubles.

2. Write a method that returns the String "regular" if all the rows of a two - dimensional array of floats have the same number of coumns; otherwise, it returns "irregular".

3. Write a method that returns the concatenation of all elements in a two - dimensional array of Strings.

Thanks, WIll Plus REP A TONNN!!!
#2. Posted:
Feargoyle
  • TTG Addict
Status: Offline
Joined: Dec 09, 200915Year Member
Posts: 2,075
Reputation Power: 250
Status: Offline
Joined: Dec 09, 200915Year Member
Posts: 2,075
Reputation Power: 250
I'm sure people would be happy to help you, including me. But only if you show some attempt at the problems yourself.
#3. Posted:
yoseaweed
  • Prospect
Status: Offline
Joined: Aug 04, 201014Year Member
Posts: 608
Reputation Power: 25
Status: Offline
Joined: Aug 04, 201014Year Member
Posts: 608
Reputation Power: 25
Feargoyle wrote I'm sure people would be happy to help you, including me. But only if you show some attempt at the problems yourself.


Ok I did the first one. I'm stuck on number 2. Here's what I think:
If rows = columns
then, print out regular.
else rows does not = columns
then, printout irregular.

and for number 3, im really confused....
#4. Posted:
CoNdEmR
  • Blind Luck
Status: Offline
Joined: Apr 29, 200915Year Member
Posts: 4,420
Reputation Power: 1211
Status: Offline
Joined: Apr 29, 200915Year Member
Posts: 4,420
Reputation Power: 1211
yoseaweed wrote
Feargoyle wrote I'm sure people would be happy to help you, including me. But only if you show some attempt at the problems yourself.


Ok I did the first one. I'm stuck on number 2. Here's what I think:
If rows = columns
then, print out regular.
else rows does not = columns
then, printout irregular.

and for number 3, im really confused....


What he means is post what code you have written thus far. We are not here to spoon feed you, and will not do your work for you.
#5. Posted:
Logiztics
  • Junior Member
Status: Offline
Joined: Apr 07, 201212Year Member
Posts: 51
Reputation Power: 2
Status: Offline
Joined: Apr 07, 201212Year Member
Posts: 51
Reputation Power: 2
This is number 3:

import java.util.Random;
import java.util.Scanner;
public class concatArray {
private static Random r = new Random();
private static String letter;
private static StringBuffer array = new StringBuffer();
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int arrayRow, arrayColumn, random;
String find[][];

System.out.println("Enter the amount of Rows in the array, then Columns: ");
arrayRow = input.nextInt();
arrayColumn = input.nextInt();

find = new String[arrayRow][arrayColumn];

for(int x = 0; x < find.length; x ++){
for(int i = 0; i < find[x].length; i ++){
random = r.nextInt(10) + 1;
getLetter(random);
find[x][i] = letter;
}
}
concatArray(find);
}
private static void concatArray(String[][] find) {
for(int x = 0; x < find.length; x++){
for(int i = 0; i < find[x].length; i++){
array = array.append(find[x][i] + ", ");
}
}
System.out.print(array);
}
private static void getLetter(int i) {
switch(i){
case 1: letter = "A"; break;
case 2: letter = "B"; break;
case 3: letter = "C"; break;
case 4: letter = "D"; break;
case 5: letter = "E"; break;
case 6: letter = "F"; break;
case 7: letter = "G"; break;
case 8: letter = "H"; break;
case 9: letter = "I"; break;
case 10: letter = "J"; break;
default: letter = "Unknown"; break;
}

}

}


*Not in the code:
I used String Buffer because I didn't want to concat everything together and by the way concat means you add to strings to one another for example:

String s1 = "a";
String s2 = "b";
String s3 = s1.concat(s2);
------------------------------------------------------------------------------------------------------
Also stringbuffer basically is essentially a string except unlike a string joins strings together instead of just deleting a string and creating a new one every time you make a change to a string. Therefore StringBuffer is just way easier to use instead of concat.
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.