Newbie here, first time programmer. I have a homework assignment that I am working on. Instructions:
Write an application that allows input of an integer n between 1 and 71, and (using a for or while loop, or loops) outputs 1 asterisk on the first line of output, 2 asterisks on the second line of output, etc., through n asterisks on the nth line of output. Allow the value of n to be 1 but not 71. HINT: Use a nested loop structure.
My Code:
import java.util.Scanner;
public class Lab6a_JamesVirden
{
public static void main(String args[])
{
int n;
int sum;
int cnt;
sum = 0;
cnt = 0;
Scanner input = new Scanner(System.in);
System.out.println();
System.out.println();
System.out.print("Input the total number of lines to output as anyinterger greater than 0 and less than 71: ");
n = input.nextInt();
for(i = 0: i < 71; i++)
{
if ((n > 0) && (n < 71))
{
System.out.println("*" + cnt++);
}
else
{
System.out.println("The number you entered is out of range.");
System.out.print("Input the total number of lines to output as any interger greater than 1 and less than 71: ");
n = input.nextInt();
}
}
System.out.println("Press any key to continue...");
}
}
According to the assignment instructions, my output should display the * on line one, ** on the next line (line 2), * (line 3), etc, n = input.nextInt() is reached. Example: if n=5, output should be 5 lines beginning with one * on the first, two * on the second, etc until the output has reached 5 lines with five * on the fifth line. I am certain I am getting close, however my output which is printed isn't print multiple * on each line. Instead it is printing n*.
Any help is much appreciated. Thank you for your time.
forloop,while,do/whileloop) for statements (such asifstatement). :) – HelpNeeder Sep 21 '12 at 11:10