|
Can someone tell me what I’m doing wrong. I’m currently a Java student and my assignment is to write a program printing *’s on a line, the number of *’s to print on each line is entered by the end user. This program must accept 5 integer values of numbers from 1 to 30 and print that number of *’s on a line, when each integer is entered, the next set of *’s must print on the next line. The code that I currently have isn’t taking the \n to go to the next line, it is printing boxes between my output screen in the applet. I’m putting the *’s into a string field called output, then when the line is filled with *’s, I’m adding \n to the output field to go to the next line for the next line of *’s, until I have five lines. But what I’m actually getting is, *’s separated by boxes all on one line. Can’t figure out how to get the drawString to accept the \n (new line) escape character? Thanks
if((iInteger > 0) && (iInteger <= 30)) { // count 5 rows for ( int row=1; row <= 5; row++ ) { // count columns until integer entered is obtained for ( int column = 1; column <= iInteger ; column++ ) { output += "*"; } // end inner for structure output += “\n”; iInteger = 0; sInteger = JOptionPane.showInputDialog("Enter an interger between 1 and 30: "); iInteger = Integer.parseInt(sInteger);
} // end outer for structure
g.drawString(output, 10, 10); }//end <=30 |