Hi there,
This is my first post in the forums. Honestly I need your help.
I'm a beginner at programming java. Currently studying systems engineering of course.
I'll be happy to help you out when I become a little more knowledgable.
Problem:
I am having this issue displayed in the cmd:
Asterisco.java:42: error: 'else' without 'if'
else if ( c <= 1 )
^
Asterisco.java:64: error: while expected
}
^
Asterisco.java:68: error: reached end of file while parsing
3 errors
Brief Overview of Program:
The program prints a given number of * within a line, and then continues printing this line a given number of times.
The number of * printed together in a line are the colums or columnas in spanish.
The number of lines of * printed are the rows or lineas in spanish.
An example should look like this in the cmd;
Columns (Columnas): 4
Rows (Lineas): 7
****
****
****
****
****
****
****
Code of program:
import java.util.Scanner; public class Asterisco{ public static void main(String[] args ){ Scanner sc = new Scanner(System.in); int c; int l; char r; int contern; String Aster = "*"; contern = 2; do{ //Openning message System.out.println( " \n\n Fecha de Creacion: 30 de Enero del 2013\n Autor: Andrew J. Redican " ); System.out.println( " \n\n Bienvenido al Asterisco. \n Por favor, ingrese los datos requeridos. \n \n " ); // Requesting values System.out.println( "Numero de columnas: "); c = sc.nextInt(); System.out.println( "Numero de lineas: "); l = sc.nextInt(); // If any values are 0 then do nothing. if ( c > 0 && l > 0 ) { if ( c > 1 ) { while ( contern <= c ) { Aster = Aster + Aster; contern++; } for ( int k=1; k <= l; k++) { System.out.println( Aster ); } else if ( c <= 1 ) { for ( int k=1; k <= l; k++) { System.out.println( Aster ); } } Aster = "*"; } System.out.println( "\n Desea ejectuar el programa otra vez? S para Si, N para No: \n " ); r = sc.next().charAt(0); } while (r == 'S' || r == 's' ); //Closing message System.out.println( " \n\n Gracias por usar Asterisco.java :)\n\n\n\n\n\n" ); } }
Another Doubt:
Am I able to add Strings?
For example:
String word;
word = "wa";
word = word + word;
If I can't do that I'll have to think another way of add a given number of times "*" next to each other and then print it in my program.
I hope you can give me a hand.