![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Sep 2004
Posts: 1
Rep Power: 0
![]() |
I have to code something which will take in an integer input from a file. Then it will read that many strings, and output them onto the console as triangles. Here are some examples:
SAMPLE INPUT: 3 ONE FRED A SAMPLE OUTPUT: * O N *N ENONE * *F * R R *E * E DERFRED A My code keeps blowing up on me. Can anyone help me out? import java.util.*;
import java.io.*;
public class Triangle{
public static void main(String[]args) throws IOException{
Scanner keyboard = new Scanner(new File("pr9a.dat"));
int sets = keyboard.nextInt();
keyboard.nextLine();
for(int i=0; i<sets; i++){
String buffer = keyboard.nextLine();
int length = buffer.length();
char stringMatrix[][] = new char[length][length+length-1];
int offset = length;
for(int j=0; j<length; j++){
stringMatrix[j][offset+j] = buffer.charAt(j);
stringMatrix[j][offset-j] = buffer.charAt(j);
offset++;
}
for(int r = 0; r<length; r++){
for(int c = 0; c<length+length-1; c++){
System.out.print(stringMatrix[r][c]);
}
System.out.println();
}
}
}
} |
|
|
|
|
|
#2 |
|
Programmer
|
What exactly do you mean by blowing up on you?
__________________
Free Porn!! |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|