Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Reformatting Java source code) Write a program that converts the Java source cod

ID: 3633970 • Letter: R

Question

Reformatting Java source code) Write a program that converts the Java
source code from the next-line brace style to the end-of-line brace
style. For example, the Java source here uses next-line brace style:
public class Test
{
public static void main(String[] args)
{
//Some statements
}
}
Your program should convert that code to end-of-line style:
public class Test {
public static void main(String[] args) {
//Some statements
}
}
Your program can be invoked from the command line with the Java
source code file as the argument. It converts the Java source code
to a new format. For example, the following command converts the
Java source code file Test.java to the end-of-line brace style:
java CodeConverter Test.java

Explanation / Answer

please rate - thanks

import java.util.*;
import java.io.*;
public class commandout
{
public static void main(String[] args)throws IOException
{String text;
boolean prev=false;
Scanner input=new Scanner(new File(args[0]));
while(input.hasNextLine())
{text=input.nextLine();
if(text.charAt(0)=='{')
    {System.out.println("{");
    prev=true;
    }
else
    {if(!prev)
         System.out.println();
    System.out.print(text);
    prev=false;
    }
}
input.close();
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote