here is my first attempt:
-
import java.io.*;
-
import java.util.*;
-
-
publc class MagicPrinter
-
{
-
publc static void main(String[] args);
-
{
-
String inputString;
-
double num1;
-
char a = "*";
-
-
//for the input stream
-
InputStreamReader isr = new InputStreamReader(System.in);
-
//needed to use ReadLine()
-
BufferedReader br = new BufferedReader(isr);
-
-
System.out.println("How many lines? ";
-
inputString = br.readLine();
-
-
do{
-
for(num 1 == 1;num1>3; a++){
-
for(num1 ==1;num3<80;a++){
-
System.out.print(a++);
-
}
-
}
-
}
-
Hello,
First of all taking one look at your program I can say you must be getting more than a few compile time errors!
-Giving a ';' after main()? That will make it abstract and its body will be ignored.
-A character literal needs to be enclosed in single quotes(' ') not double(" ").
-The method readLine() is capable of throwing an 'IOException'.This exception is a type of 'Java Checked Exception', such type of exceptions must be handled in a try-catch block or declared to be thrown.
- for(num1 == 1) is incorrect.
'==' is for comparision and '=' is for assignment.
Structure of a 'for' loop is :
for (initialization; termination; increment) {
statement(s)
}
The first expression of the for loop is for initialization, but instead if you carry out comparision you'll definitely get an error.
-num3<80 ?
What is num3?Where is it declared?
- There is no do-loop in Java, the loops that we have are for,while,do-while.
Please compile your program and take a good look at the exceptions you are getting, try to sort them out one by one first. If you don't understand any exception post it.
As for the logic:
say there are 3 lines then -
line 1: one *
line 2: two *'s
line 3: three *'s
See the connection between the line number and the corresponding number of stars in it.
Now generalize it.