diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..13ef7c4
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,14 @@
+
-* GraphViz gv = new GraphViz(); -* gv.addln(gv.start_graph()); -* gv.addln("A -> B;"); -* gv.addln("A -> C;"); -* gv.addln(gv.end_graph()); -* System.out.println(gv.getDotSource()); -* -* String type = "gif"; -* File out = new File("out." + type); // out.gif in this example -* gv.writeGraphToFile( gv.getGraph( gv.getDotSource(), type ), out ); -*-*
+ * GraphViz gv = new GraphViz(); + * gv.addln(gv.start_graph()); + * gv.addln("A -> B;"); + * gv.addln("A -> C;"); + * gv.addln(gv.end_graph()); + * System.out.println(gv.getDotSource()); + * + * String type = "gif"; + * File out = new File("out." + type); // out.gif in this example + * gv.writeGraphToFile( gv.getGraph( gv.getDotSource(), type ), out ); + *+ *
+ * dpi patch by Peter Mueller
+ */
+ private int[] dpiSizes = {46, 51, 57, 63, 70, 78, 86, 96, 106, 116, 128, 141, 155, 170, 187, 206, 226, 249};
- /**
- * Increase the image size (dpi).
- */
- public void increaseDpi() {
- if ( this.currentDpiPos < (this.dpiSizes.length - 1) ) {
- ++this.currentDpiPos;
- }
- }
+ /**
+ * Define the index in the image size array.
+ */
+ private int currentDpiPos = 7;
- /**
- * Decrease the image size (dpi).
- */
- public void decreaseDpi() {
- if (this.currentDpiPos > 0) {
- --this.currentDpiPos;
- }
- }
+ /**
+ * Increase the image size (dpi).
+ */
+ public void increaseDpi() {
+ if (this.currentDpiPos < (this.dpiSizes.length - 1)) {
+ ++this.currentDpiPos;
+ }
+ }
- public int getImageDpi() {
- return this.dpiSizes[this.currentDpiPos];
- }
+ /**
+ * Decrease the image size (dpi).
+ */
+ public void decreaseDpi() {
+ if (this.currentDpiPos > 0) {
+ --this.currentDpiPos;
+ }
+ }
- /**
- * The source of the graph written in dot language.
- */
- private StringBuilder graph = new StringBuilder();
+ public int getImageDpi() {
+ return this.dpiSizes[this.currentDpiPos];
+ }
- /**
- * Constructor: creates a new GraphViz object that will contain
- * a graph.
- */
- public GraphViz() {
- }
+ /**
+ * The source of the graph written in dot language.
+ */
+ private StringBuilder graph = new StringBuilder();
- /**
- * Returns the graph's source description in dot language.
- * @return Source of the graph in dot language.
- */
- public String getDotSource() {
- return this.graph.toString();
- }
+ /**
+ * Constructor: creates a new GraphViz object that will contain
+ * a graph.
+ */
+ public GraphViz() {
+ }
- /**
- * Adds a string to the graph's source (without newline).
- */
- public void add(String line) {
- this.graph.append(line);
- }
+ /**
+ * Returns the graph's source description in dot language.
+ *
+ * @return Source of the graph in dot language.
+ */
+ public String getDotSource() {
+ return this.graph.toString();
+ }
- /**
- * Adds a string to the graph's source (with newline).
- */
- public void addln(String line) {
- this.graph.append(line).append("\n");
- }
+ /**
+ * Adds a string to the graph's source (without newline).
+ */
+ public void add(String line) {
+ this.graph.append(line);
+ }
- /**
- * Adds a newline to the graph's source.
- */
- public void addln() {
- this.graph.append('\n');
- }
+ /**
+ * Adds a string to the graph's source (with newline).
+ */
+ public void addln(String line) {
+ this.graph.append(line).append("\n");
+ }
- public void clearGraph(){
- this.graph = new StringBuilder();
- }
+ /**
+ * Adds a newline to the graph's source.
+ */
+ public void addln() {
+ this.graph.append('\n');
+ }
- /**
- * Returns the graph as an image in binary format.
- * @param dot_source Source of the graph to be drawn.
- * @param type Type of the output image to be produced, e.g.: gif, dot, fig, pdf, ps, svg, png.
- * @return A byte array containing the image of the graph.
- */
- public byte[] getGraph(String dot_source, String type)
- {
- File dot;
- byte[] img_stream;
+ public void clearGraph() {
+ this.graph = new StringBuilder();
+ }
- try {
- dot = writeDotSourceToFile(dot_source);
- if (dot != null)
- {
- img_stream = get_img_stream(dot, type);
- if (!dot.delete())
- System.err.println("Warning: " + dot.getAbsolutePath() + " could not be deleted!");
- return img_stream;
- }
- return null;
- } catch (java.io.IOException ioe) { return null; }
- }
+ /**
+ * Returns the graph as an image in binary format.
+ *
+ * @param dot_source Source of the graph to be drawn.
+ * @param type Type of the output image to be produced, e.g.: gif, dot, fig, pdf, ps, svg, png.
+ * @return A byte array containing the image of the graph.
+ */
+ public byte[] getGraph(String dot_source, String type) {
+ File dot;
+ byte[] img_stream;
- /**
- * Writes the graph's image in a file.
- * @param img A byte array containing the image of the graph.
- * @param file Name of the file to where we want to write.
- * @return Success: 1, Failure: -1
- */
- public int writeGraphToFile(byte[] img, String file)
- {
- File to = new File(file);
- return writeGraphToFile(img, to);
- }
+ try {
+ dot = writeDotSourceToFile(dot_source);
+ if (dot != null) {
+ img_stream = get_img_stream(dot, type);
+ if (!dot.delete())
+ System.err.println("Warning: " + dot.getAbsolutePath() + " could not be deleted!");
+ return img_stream;
+ }
+ return null;
+ } catch (java.io.IOException ioe) {
+ return null;
+ }
+ }
- /**
- * Writes the graph's image in a file.
- * @param img A byte array containing the image of the graph.
- * @param to A File object to where we want to write.
- * @return Success: 1, Failure: -1
- */
- public int writeGraphToFile(byte[] img, File to)
- {
- try {
- FileOutputStream fos = new FileOutputStream(to);
- fos.write(img);
- fos.close();
- } catch (java.io.IOException ioe) { return -1; }
- return 1;
- }
+ /**
+ * Writes the graph's image in a file.
+ *
+ * @param img A byte array containing the image of the graph.
+ * @param file Name of the file to where we want to write.
+ * @return Success: 1, Failure: -1
+ */
+ public int writeGraphToFile(byte[] img, String file) {
+ File to = new File(file);
+ return writeGraphToFile(img, to);
+ }
- /**
- * It will call the external dot program, and return the image in
- * binary format.
- * @param dot Source of the graph (in dot language).
- * @param type Type of the output image to be produced, e.g.: gif, dot, fig, pdf, ps, svg, png.
- * @return The image of the graph in .gif format.
- */
- private byte[] get_img_stream(File dot, String type)
- {
- File img;
- byte[] img_stream = null;
+ /**
+ * Writes the graph's image in a file.
+ *
+ * @param img A byte array containing the image of the graph.
+ * @param to A File object to where we want to write.
+ * @return Success: 1, Failure: -1
+ */
+ public int writeGraphToFile(byte[] img, File to) {
+ try {
+ FileOutputStream fos = new FileOutputStream(to);
+ fos.write(img);
+ fos.close();
+ } catch (java.io.IOException ioe) {
+ return -1;
+ }
+ return 1;
+ }
- try {
- img = File.createTempFile("graph_", "."+type, new File(GraphViz.TEMP_DIR));
- Runtime rt = Runtime.getRuntime();
+ /**
+ * It will call the external dot program, and return the image in
+ * binary format.
+ *
+ * @param dot Source of the graph (in dot language).
+ * @param type Type of the output image to be produced, e.g.: gif, dot, fig, pdf, ps, svg, png.
+ * @return The image of the graph in .gif format.
+ */
+ private byte[] get_img_stream(File dot, String type) {
+ File img;
+ byte[] img_stream = null;
- // patch by Mike Chenault
- String[] args = {DOT, "-T"+type, "-Gdpi="+dpiSizes[this.currentDpiPos], dot.getAbsolutePath(), "-o", img.getAbsolutePath()};
- Process p = rt.exec(args);
+ try {
+ img = File.createTempFile("graph_", "." + type, new File(GraphViz.TEMP_DIR));
+ Runtime rt = Runtime.getRuntime();
- p.waitFor();
+ // patch by Mike Chenault
+ String[] args = {DOT, "-T" + type, "-Gdpi=" + dpiSizes[this.currentDpiPos], dot.getAbsolutePath(), "-o", img.getAbsolutePath()};
+ Process p = rt.exec(args);
- FileInputStream in = new FileInputStream(img.getAbsolutePath());
- img_stream = new byte[in.available()];
- in.read(img_stream);
- // Close it if we need to
- in.close();
+ p.waitFor();
- if (!img.delete())
- System.err.println("Warning: " + img.getAbsolutePath() + " could not be deleted!");
- }
- catch (java.io.IOException ioe) {
- System.err.println("Error: in I/O processing of tempfile in dir " + GraphViz.TEMP_DIR+"\n");
- System.err.println(" or in calling external command");
- ioe.printStackTrace();
- }
- catch (java.lang.InterruptedException ie) {
- System.err.println("Error: the execution of the external program was interrupted");
- ie.printStackTrace();
- }
+ FileInputStream in = new FileInputStream(img.getAbsolutePath());
+ img_stream = new byte[in.available()];
+ in.read(img_stream);
+ // Close it if we need to
+ in.close();
- return img_stream;
- }
+ if (!img.delete())
+ System.err.println("Warning: " + img.getAbsolutePath() + " could not be deleted!");
+ } catch (java.io.IOException ioe) {
+ System.err.println("Error: in I/O processing of tempfile in dir " + GraphViz.TEMP_DIR + "\n");
+ System.err.println(" or in calling external command");
+ ioe.printStackTrace();
+ } catch (java.lang.InterruptedException ie) {
+ System.err.println("Error: the execution of the external program was interrupted");
+ ie.printStackTrace();
+ }
- /**
- * Writes the source of the graph in a file, and returns the written file
- * as a File object.
- * @param str Source of the graph (in dot language).
- * @return The file (as a File object) that contains the source of the graph.
- */
- private File writeDotSourceToFile(String str) throws java.io.IOException
- {
- File temp;
- try {
- temp = File.createTempFile("dorrr",".dot", new File(GraphViz.TEMP_DIR));
- FileWriter fout = new FileWriter(temp);
- fout.write(str);
- BufferedWriter br=new BufferedWriter(new FileWriter("/tmp/dotsource.dot"));
- br.write(str);
- br.flush();
- br.close();
- fout.close();
- }
- catch (Exception e) {
- System.err.println("Error: I/O error while writing the dot source to temp file!");
- return null;
- }
- return temp;
- }
+ return img_stream;
+ }
- /**
- * Returns a string that is used to start a graph.
- * @return A string to open a graph.
- */
- public String start_graph() {
- return "digraph G {";
- }
+ /**
+ * Writes the source of the graph in a file, and returns the written file
+ * as a File object.
+ *
+ * @param str Source of the graph (in dot language).
+ * @return The file (as a File object) that contains the source of the graph.
+ */
+ private File writeDotSourceToFile(String str) throws java.io.IOException {
+ File temp;
+ try {
+ temp = File.createTempFile("dorrr", ".dot", new File(GraphViz.TEMP_DIR));
+ FileWriter fout = new FileWriter(temp);
+ fout.write(str);
+ BufferedWriter br = new BufferedWriter(new FileWriter("/tmp/dotsource.dot"));
+ br.write(str);
+ br.flush();
+ br.close();
+ fout.close();
+ } catch (Exception e) {
+ System.err.println("Error: I/O error while writing the dot source to temp file!");
+ return null;
+ }
+ return temp;
+ }
- /**
- * Returns a string that is used to end a graph.
- * @return A string to close a graph.
- */
- public String end_graph() {
- return "}";
- }
+ /**
+ * Returns a string that is used to start a graph.
+ *
+ * @return A string to open a graph.
+ */
+ public String start_graph() {
+ return "digraph G {";
+ }
- /**
- * Takes the cluster or subgraph id as input parameter and returns a string
- * that is used to start a subgraph.
- * @return A string to open a subgraph.
- */
- public String start_subgraph(int clusterid) {
- return "subgraph cluster_" + clusterid + " {";
- }
+ /**
+ * Returns a string that is used to end a graph.
+ *
+ * @return A string to close a graph.
+ */
+ public String end_graph() {
+ return "}";
+ }
- /**
- * Returns a string that is used to end a graph.
- * @return A string to close a graph.
- */
- public String end_subgraph() {
- return "}";
- }
+ /**
+ * Takes the cluster or subgraph id as input parameter and returns a string
+ * that is used to start a subgraph.
+ *
+ * @return A string to open a subgraph.
+ */
+ public String start_subgraph(int clusterid) {
+ return "subgraph cluster_" + clusterid + " {";
+ }
- /**
- * Read a DOT graph from a text file.
- *
- * @param input Input text file containing the DOT graph
- * source.
- */
- public void readSource(String input)
- {
- StringBuilder sb = new StringBuilder();
+ /**
+ * Returns a string that is used to end a graph.
+ *
+ * @return A string to close a graph.
+ */
+ public String end_subgraph() {
+ return "}";
+ }
- try
- {
- FileInputStream fis = new FileInputStream(input);
- DataInputStream dis = new DataInputStream(fis);
- BufferedReader br = new BufferedReader(new InputStreamReader(dis));
- String line;
- while ((line = br.readLine()) != null) {
- sb.append(line);
- }
- dis.close();
- }
- catch (Exception e) {
- System.err.println("Error: " + e.getMessage());
- }
+ /**
+ * Read a DOT graph from a text file.
+ *
+ * @param input Input text file containing the DOT graph
+ * source.
+ */
+ public void readSource(String input) {
+ StringBuilder sb = new StringBuilder();
- this.graph = sb;
- }
+ try {
+ FileInputStream fis = new FileInputStream(input);
+ DataInputStream dis = new DataInputStream(fis);
+ BufferedReader br = new BufferedReader(new InputStreamReader(dis));
+ String line;
+ while ((line = br.readLine()) != null) {
+ sb.append(line);
+ }
+ dis.close();
+ } catch (Exception e) {
+ System.err.println("Error: " + e.getMessage());
+ }
+
+ this.graph = sb;
+ }
} // end of class GraphViz
diff --git a/src/main/java/grafos/Transformador.java b/src/main/java/grafos/Transformador.java
index 691bb3f..4f03edf 100644
--- a/src/main/java/grafos/Transformador.java
+++ b/src/main/java/grafos/Transformador.java
@@ -1,79 +1,77 @@
package grafos;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
import com.github.javaparser.JavaParser;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.comments.Comment;
import com.github.javaparser.ast.visitor.VoidVisitor;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
public class Transformador {
public static void main(String[] args) throws Exception {
// Ruta del fichero con el programa que vamos a transformar
String ruta = "./src/test/res/ejemplos/Test_1";
-
+
// Abrimos el fichero original (un ".java")
File original = new File(ruta + ".java");
-
+
// Parseamos el fichero original. Se crea una unidad de compilación (un AST).
CompilationUnit cu = JavaParser.parse(original);
-
+
quitarComentarios(cu);
-
+
// Recorremos el AST
List> visitador = new Visitador();
- visitador.visit(cu,arcos);
-
+ visitador.visit(cu, arcos);
+
// Imprimimos el CFG del programa
String dotInfo = imprimirGrafo(arcos);
-
+
// Generamos un PDF con el CFG del programa
System.out.print("\nGenerando PDF...");
- GraphViz gv=new GraphViz();
- gv.addln(gv.start_graph());
- gv.add(dotInfo);
- gv.addln(gv.end_graph());
- String type = "pdf"; // String type = "gif";
- // gv.increaseDpi();
- gv.decreaseDpi();
- gv.decreaseDpi();
- gv.decreaseDpi();
- gv.decreaseDpi();
- File destino_CFG = new File(ruta + "_CFG."+ type);
- gv.writeGraphToFile( gv.getGraph( gv.getDotSource(), type ), destino_CFG);
- System.out.println(" PDF generado!");
+ GraphViz gv = new GraphViz();
+ gv.addln(gv.start_graph());
+ gv.add(dotInfo);
+ gv.addln(gv.end_graph());
+ String type = "pdf"; // String type = "gif";
+ // gv.increaseDpi();
+ gv.decreaseDpi();
+ gv.decreaseDpi();
+ gv.decreaseDpi();
+ gv.decreaseDpi();
+ File destino_CFG = new File(ruta + "_CFG." + type);
+ gv.writeGraphToFile(gv.getGraph(gv.getDotSource(), type), destino_CFG);
+ System.out.println(" PDF generado!");
}
// Imprime el grafo en la pantalla
- private static String imprimirGrafo(List
>
-{
+
+public class Visitador extends VoidVisitorAdapter
> {
//********************************************************/
//********************** Atributos ***********************/
//********************************************************/
-
+
// Usamos un contador para numerar las instrucciones
- private int contador=1;
+ private int contador = 1;
private String nodoAnterior = "Start";
private String nodoActual = "";
-
+
//********************************************************/
//*********************** Metodos ************************/
//********************************************************/
- // Visitador de métodos
+ // Visitador de métodos
// Este visitador añade el nodo final al CFG
- @Override
- public void visit(MethodDeclaration methodDeclaration, List
>
return block;
}
-
+
}
diff --git a/src/test/res/ejemplos/Bucles_1.java b/src/test/res/ejemplos/Bucles_1.java
index f3f00eb..664ab83 100755
--- a/src/test/res/ejemplos/Bucles_1.java
+++ b/src/test/res/ejemplos/Bucles_1.java
@@ -2,15 +2,13 @@ package ejemplos;
public class Bucles_1 {
- public static void main(String[] args)
- {
+ public static void main(String[] args) {
// BUCLE WHILE (sin anidamiento)
- int x=1;
- while (x<=10)
- {
+ int x = 1;
+ while (x <= 10) {
System.out.print(x);
x++;
}
- System.out.println();
+ System.out.println();
}
}
diff --git a/src/test/res/ejemplos/Bucles_2.java b/src/test/res/ejemplos/Bucles_2.java
index 60d4e51..3d388e2 100755
--- a/src/test/res/ejemplos/Bucles_2.java
+++ b/src/test/res/ejemplos/Bucles_2.java
@@ -2,19 +2,16 @@ package ejemplos;
public class Bucles_2 {
- public static void main(String[] args)
- {
+ public static void main(String[] args) {
// BUCLE WHILE anidado a otro WHILE
- System.out.println("Empieza bucle WHILE anidado a otro WHILE:");
- int x=1;
- char y='a';
- while (x<=10)
- {
- System.out.print(" "+x);
- y='a';
- while (y<='c')
- {
- System.out.print(" "+y);
+ System.out.println("Empieza bucle WHILE anidado a otro WHILE:");
+ int x = 1;
+ char y = 'a';
+ while (x <= 10) {
+ System.out.print(" " + x);
+ y = 'a';
+ while (y <= 'c') {
+ System.out.print(" " + y);
y++;
}
x++;
diff --git a/src/test/res/ejemplos/Bucles_3.java b/src/test/res/ejemplos/Bucles_3.java
index fedefc7..96e4d86 100755
--- a/src/test/res/ejemplos/Bucles_3.java
+++ b/src/test/res/ejemplos/Bucles_3.java
@@ -4,34 +4,32 @@ public class Bucles_3 {
public static void main(String[] args) {
int x;
-
+
// BUCLE FOR (sin anidamiento)
- System.out.println("Empieza bucle FOR:");
- for (x=1;x<=10;x++)
- {
- System.out.print(" "+x);
+ System.out.println("Empieza bucle FOR:");
+ for (x = 1; x <= 10; x++) {
+ System.out.print(" " + x);
}
System.out.println();
// BUCLE WHILE (sin anidamiento)
- System.out.println("Empieza bucle WHILE:");
- x=1;
- while (x<=10)
- {
- System.out.print(" "+x);
+ System.out.println("Empieza bucle WHILE:");
+ x = 1;
+ while (x <= 10) {
+ System.out.print(" " + x);
x++;
}
System.out.println();
// BUCLE DO WHILE (sin anidamiento)
- System.out.println("Empieza bucle DO WHILE:");
- x=1;
- do{
- System.out.print(" "+x);
+ System.out.println("Empieza bucle DO WHILE:");
+ x = 1;
+ do {
+ System.out.print(" " + x);
x++;
}
- while (x<=10);
+ while (x <= 10);
System.out.println();
-
+
}
}
diff --git a/src/test/res/ejemplos/Bucles_4.java b/src/test/res/ejemplos/Bucles_4.java
index 0d844b3..9f3c130 100755
--- a/src/test/res/ejemplos/Bucles_4.java
+++ b/src/test/res/ejemplos/Bucles_4.java
@@ -2,22 +2,19 @@ package ejemplos;
public class Bucles_4 {
- public static void main(String[] args)
- {
- int x=1;
-
+ public static void main(String[] args) {
+ int x = 1;
+
//Bucle 1: Contador
- while (x<10)
- {
+ while (x < 10) {
System.out.println(x);
x++;
}
//Bucle 2: Sumatorio
- int suma=0;
- int y=1;
- while (y<10)
- {
+ int suma = 0;
+ int y = 1;
+ while (y < 10) {
suma += y;
y++;
}
@@ -27,8 +24,7 @@ public class Bucles_4 {
int sumatorio = 0;
int min = 10;
int max = 100;
- for (int num = min; num <= max; num++)
- {
+ for (int num = min; num <= max; num++) {
sumatorio += num;
}
System.out.println(sumatorio);
diff --git a/src/test/res/ejemplos/Bucles_5.java b/src/test/res/ejemplos/Bucles_5.java
index b8558cd..e54d85e 100755
--- a/src/test/res/ejemplos/Bucles_5.java
+++ b/src/test/res/ejemplos/Bucles_5.java
@@ -5,29 +5,25 @@ public class Bucles_5 {
public static void main(String[] args) {
int x = 0;
char y = '0';
-
+
// BUCLE FOR anidado a otro FOR
- System.out.println("Empieza bucle FOR anidado a otro FOR:");
- for (x=1;x<=10;x++)
- {
- System.out.print(" "+x);
- for (y='a';y<='c';y++)
- {
- System.out.print(" "+y);
+ System.out.println("Empieza bucle FOR anidado a otro FOR:");
+ for (x = 1; x <= 10; x++) {
+ System.out.print(" " + x);
+ for (y = 'a'; y <= 'c'; y++) {
+ System.out.print(" " + y);
}
}
System.out.println();
// BUCLE WHILE anidado a otro WHILE
- System.out.println("Empieza bucle WHILE anidado a otro WHILE:");
- x=1;
- while (x<=10)
- {
- System.out.print(" "+x);
- y='a';
- while (y<='c')
- {
- System.out.print(" "+y);
+ System.out.println("Empieza bucle WHILE anidado a otro WHILE:");
+ x = 1;
+ while (x <= 10) {
+ System.out.print(" " + x);
+ y = 'a';
+ while (y <= 'c') {
+ System.out.print(" " + y);
y++;
}
x++;
@@ -35,18 +31,17 @@ public class Bucles_5 {
System.out.println();
// BUCLE FOR anidado a bucle DO WHILE
- System.out.println("Empieza bucle FOR anidado a bucle DO WHILE:");
- x=1;
- do{
- System.out.print(" "+x);
- for (y='a';y<='c';y++)
- {
- System.out.print(" "+y);
+ System.out.println("Empieza bucle FOR anidado a bucle DO WHILE:");
+ x = 1;
+ do {
+ System.out.print(" " + x);
+ for (y = 'a'; y <= 'c'; y++) {
+ System.out.print(" " + y);
}
x++;
}
- while (x<=10);
+ while (x <= 10);
System.out.println();
-
+
}
}
diff --git a/src/test/res/ejemplos/Bucles_6.java b/src/test/res/ejemplos/Bucles_6.java
index a6df9d8..9ba83b5 100644
--- a/src/test/res/ejemplos/Bucles_6.java
+++ b/src/test/res/ejemplos/Bucles_6.java
@@ -2,26 +2,22 @@ package ejemplos;
public class Bucles_6 {
- public static void main(String[] args)
- {
+ public static void main(String[] args) {
// BUCLE WHILE (sin anidamiento)
- System.out.println("Empieza bucle WHILE:");
- int x=1;
- while (x<=10)
- {
- System.out.print(" "+x);
+ System.out.println("Empieza bucle WHILE:");
+ int x = 1;
+ while (x <= 10) {
+ System.out.print(" " + x);
x++;
- while (x<=10)
- {
- System.out.print(" "+x);
+ while (x <= 10) {
+ System.out.print(" " + x);
x++;
}
}
- while (x<=10)
- {
- System.out.print(" "+x);
+ while (x <= 10) {
+ System.out.print(" " + x);
x++;
}
- System.out.println();
+ System.out.println();
}
}
diff --git a/src/test/res/ejemplos/Test_1.java b/src/test/res/ejemplos/Test_1.java
index 9e387eb..7264be0 100644
--- a/src/test/res/ejemplos/Test_1.java
+++ b/src/test/res/ejemplos/Test_1.java
@@ -2,12 +2,11 @@ package ejemplos;
public class Test_1 {
- public static void main(String[] args)
- {
+ public static void main(String[] args) {
System.out.println("HOLA mundo");
- int x=1;
- x=2;
- x=3;
- x=4;
+ int x = 1;
+ x = 2;
+ x = 3;
+ x = 4;
}
}
diff --git a/src/test/res/ejemplos/Test_2.java b/src/test/res/ejemplos/Test_2.java
index 4c4ee06..3ce1e38 100644
--- a/src/test/res/ejemplos/Test_2.java
+++ b/src/test/res/ejemplos/Test_2.java
@@ -2,13 +2,12 @@ package ejemplos;
public class Test_2 {
- public static void main(String[] args)
- {
- int x=1;
+ public static void main(String[] args) {
+ int x = 1;
x++;
++x;
- int y=0;
- x=x+y;
+ int y = 0;
+ x = x + y;
System.out.println(x);
}
}
diff --git a/src/test/res/ejemplos/Test_3.java b/src/test/res/ejemplos/Test_3.java
index 3d723af..e08b7f7 100644
--- a/src/test/res/ejemplos/Test_3.java
+++ b/src/test/res/ejemplos/Test_3.java
@@ -2,13 +2,12 @@ package ejemplos;
public class Test_3 {
- public static void main(String[] args)
- {
- int x=1;
-
- if (x==1)
- x=2;
- x=3;
- x=4;
+ public static void main(String[] args) {
+ int x = 1;
+
+ if (x == 1)
+ x = 2;
+ x = 3;
+ x = 4;
}
}
diff --git a/src/test/res/ejemplos/Test_4.java b/src/test/res/ejemplos/Test_4.java
index 60b318f..43e923c 100644
--- a/src/test/res/ejemplos/Test_4.java
+++ b/src/test/res/ejemplos/Test_4.java
@@ -2,20 +2,17 @@ package ejemplos;
public class Test_4 {
- public static void main(String[] args)
- {
- int x=1;
-
- if (x==1)
- {
- x=2;
- if (x>=1)
- {
- x=3;
- x=4;
+ public static void main(String[] args) {
+ int x = 1;
+
+ if (x == 1) {
+ x = 2;
+ if (x >= 1) {
+ x = 3;
+ x = 4;
}
}
- x=5;
- x=6;
+ x = 5;
+ x = 6;
}
}
diff --git a/src/test/res/ejemplos/Test_5.java b/src/test/res/ejemplos/Test_5.java
index 1b3fec3..4dc96e4 100644
--- a/src/test/res/ejemplos/Test_5.java
+++ b/src/test/res/ejemplos/Test_5.java
@@ -2,21 +2,18 @@ package ejemplos;
public class Test_5 {
- public static void main(String[] args)
- {
- int x=1;
-
- if (x==1)
- {
- x=2;
- if (x>=1)
- {
- x=3;
- x=4;
+ public static void main(String[] args) {
+ int x = 1;
+
+ if (x == 1) {
+ x = 2;
+ if (x >= 1) {
+ x = 3;
+ x = 4;
}
- x=5;
+ x = 5;
}
- x=6;
- x=7;
+ x = 6;
+ x = 7;
}
}
diff --git a/src/test/res/ejemplos/Test_6.java b/src/test/res/ejemplos/Test_6.java
index d47ef13..91d0e19 100644
--- a/src/test/res/ejemplos/Test_6.java
+++ b/src/test/res/ejemplos/Test_6.java
@@ -2,20 +2,16 @@ package ejemplos;
public class Test_6 {
- public static void main(String[] args)
- {
- int x=1;
-
- if (x==1)
- {
- x=2;
- x=3;
+ public static void main(String[] args) {
+ int x = 1;
+
+ if (x == 1) {
+ x = 2;
+ x = 3;
+ } else {
+ x = 4;
+ x = 5;
}
- else
- {
- x=4;
- x=5;
- }
- x=6;
+ x = 6;
}
}
diff --git a/src/test/res/ejemplos/Test_7.java b/src/test/res/ejemplos/Test_7.java
index eb81fb6..60b7f5f 100644
--- a/src/test/res/ejemplos/Test_7.java
+++ b/src/test/res/ejemplos/Test_7.java
@@ -3,21 +3,16 @@ package ejemplos;
public class Test_7 {
- public static void main(String[] args)
- {
- int x=1;
-
- if (x==1)
- {
- x=2;
- }
- else x=3;
- x=4;
- if (x==2)
- {
- x=5;
- }
- else if (x==3) x=6;
- x=7;
+ public static void main(String[] args) {
+ int x = 1;
+
+ if (x == 1) {
+ x = 2;
+ } else x = 3;
+ x = 4;
+ if (x == 2) {
+ x = 5;
+ } else if (x == 3) x = 6;
+ x = 7;
}
}
diff --git a/src/test/res/ejemplos/Test_8.java b/src/test/res/ejemplos/Test_8.java
index 839774a..92c240f 100644
--- a/src/test/res/ejemplos/Test_8.java
+++ b/src/test/res/ejemplos/Test_8.java
@@ -2,21 +2,18 @@ package ejemplos;
public class Test_8 {
- public static void main(String[] args)
- {
- int x=1;
-
- if (x==1)
- {
- x=2;
+ public static void main(String[] args) {
+ int x = 1;
+
+ if (x == 1) {
+ x = 2;
}
- x=5;
- x=6;
- if (x==2)
- {
- x=7;
+ x = 5;
+ x = 6;
+ if (x == 2) {
+ x = 7;
}
- if (x==3) x=8;
- x=9;
+ if (x == 3) x = 8;
+ x = 9;
}
}
diff --git a/src/test/res/ejemplos/Test_9.java b/src/test/res/ejemplos/Test_9.java
index a636299..95a3c53 100644
--- a/src/test/res/ejemplos/Test_9.java
+++ b/src/test/res/ejemplos/Test_9.java
@@ -2,29 +2,23 @@ package ejemplos;
public class Test_9 {
-
- public static void main(String[] args)
- {
+
+ public static void main(String[] args) {
// ANIDAMIENTO de IF y WHILE
// ANIDAMIENTO de IF y WHILE 2
-
- int x=0;
- if (x>1)
- {
- x=1;
- while (x>2)
- {
- x=2;
- while (x>3)
- {
- x=3;
- if (x>4)
- {
- x=4;
- if (x>5)
- {
- x=5;
+
+ int x = 0;
+ if (x > 1) {
+ x = 1;
+ while (x > 2) {
+ x = 2;
+ while (x > 3) {
+ x = 3;
+ if (x > 4) {
+ x = 4;
+ if (x > 5) {
+ x = 5;
}
x--;
}
@@ -34,8 +28,8 @@ public class Test_9 {
}
x--;
}
-
+
x--;
-
+
}
}