Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 1 of 1

Thread: reformatting java code problem

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Thanked 0 Times in 0 Posts

    Default reformatting java code problem

    hello, i would really apreciate any help on this one.. i have just started file i/o in java and already the homework is bugging me.
    I am to write a program that reformats java source code from the next-line brace style to the end-of-line brace style. for example the following code :
    public class Test
          public static void main(String[] args)
           // some statements

    would be reformatted to :

    public class Test{
          public static void main(String[] args){
           // some statements
    my attempted code so far is below.. i don't know if i can use concat() in this instance and if i am even doing anything right... please help.. thanks.

    import java.io.*;
    import java.util.*;
    public class Main {
    	public static void main(String[] args) throws Exception {
    		File file = new File("C:\\JackTest\\test.txt");
    	public static void format(File f) throws Exception {
    		Scanner input = new Scanner(f);
    		String[] lines = new String[7];
    		while (input.hasNext()) {
    			for (int i = 0; i < 7; i++) {
    				lines[i] = input.nextLine();
    				if (lines[i].startsWith("{")) {
    					// i am stuck here.. 
    Last edited by Fordy252; November 23rd, 2010 at 02:56 PM.

Similar Threads

  1. Java mailer programming code problem
    By shadeslayer88 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 1st, 2010, 01:21 AM
  2. problem in my code
    By wannabe in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 24th, 2010, 07:53 AM
  3. Replies: 6
    Last Post: March 18th, 2010, 08:56 PM
  4. Re: Java Newbie Code Problem
    By erinbasim in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 17th, 2010, 02:05 AM
  5. [SOLVED] Java Newbie Code Problem
    By lee in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 16th, 2010, 03:05 PM