pages:
- 1
Moja Azimi SAYS
Hello my code running prefect in my pc but in ShareCode runtime error. I'm very confused. please help me
Sirwan SAYS
Hi, probably you wanna reach a NEGATIVE-INDEX of the Array in your code, take a look at the indices and make sure this is correct.
AMiR SAYS
And also pay more attention to the input/output format. I suggest to create a testcase with more than one input block and test your app against it.
Moja Azimi SAYS
Tanx Sivan and AMiR. my code : import java.util.Scanner;
public class HelloWorld {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int number, test, g, b;
test = input.nextInt();
input.nextLine();
number = input.nextInt();
input.nextLine();
while (test-- > 0) {
String str[] = new String[number];
for (int i = 0; i < number; i++) {
str[i] = input.nextLine();
for (String part : str[i].split(" "))
System.out.print(new StringBuilder(part).reverse().toString() + " ");
System.out.println("\b");
}
if (test == 1)
System.out.println();
}
}
}
AMiR SAYS
I modified your code a little bit.
```
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int number, test, g, b;
test = input.nextInt();
input.nextLine();
while (test-- > 0) {
// YOU NEED TO READ THE NUMBER OF LINES FOR EACH INPUT BLOCK
number = input.nextInt();
input.nextLine();
String str[] = new String[number];
for (int i = 0; i < number; i++) {
str[i] = input.nextLine();
int first = 1;
for (String part : str[i].split(" ")) {
// PRINTING `\b` IS NOT SAFE. TRY TO MANAGE PRINTING THE SPACE CHARACTER
if (first == 1) first = 0;
else System.out.print(" ");
System.out.print(new StringBuilder(part).reverse().toString());
}
System.out.println();
}
// YOU NEED TO PRINT A BLANK LINE BETWEEN EACH TEST BLOCK
if (test != 0)
System.out.println();
}
}
}
```
Moja Azimi SAYS
tanx AMiR.
Login please!
In order to post something you must login first. You can use the form in the top of this page.