Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 29th, 2004, 1:15 PM   #1
redMan
Newbie
 
Join Date: Sep 2004
Posts: 1
Rep Power: 0 redMan is on a distinguished road
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();
 	}
 }
	}
}
redMan is offline   Reply With Quote
Old Sep 29th, 2004, 9:40 PM   #2
gamesage
Programmer
 
Join Date: Sep 2004
Location: Clemson, SC
Posts: 35
Rep Power: 0 gamesage is on a distinguished road
Send a message via AIM to gamesage
What exactly do you mean by blowing up on you?
__________________
Free Porn!!
gamesage is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:17 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC