this program doesnt give a triangle. all the asteriks are on a straight line instead of it to be arranged in a triangular form.
There should be a System.out.println(" ");(This would be the 14th line) and on the 13th line it should be system.out.print not system.out.printLN (I kept the "LN" in capslock just to highlight it)
So the program should look like this
import java.io.*;
class triangle{ public static void main(String[] args) { try{ BufferedReader object = new BufferedReader(new InputStreamReader(System.in)); System.out.println("enter the number"); int a= Integer.parseInt(object.readLine()); for (int i=1; i<a;i++ ){ for (int j=1; j<=i;j++ ){ System.out.print("*"); } System.out.println(""); import java.io.*;
class triangle{ public static void main(String[] args) { try{ BufferedReader object = new BufferedReader(new InputStreamReader(System.in)); System.out.println("enter the number"); int a= Integer.parseInt(object.readLine()); for (int i=1; i<a;i++ ){ for (int j=1; j<=i;j++ ){ System.out.print("*"); } System.out.print(""); System.out.println(" "); } } catch(Exception e){} } } } } catch(Exception e){} } }
View All Comments
| View Tutorial