Re: nested loop structure
I am confused as to what the requirements are. Perhaps I'm misunderstanding, but you seem to have a nested loop to print a single line.
Re: nested loop structure
What I am trying to do it print out a line based upon the number the user inputs. When a user inputs a number, it is supposed to print off that manylines of asterisks. An example of the output I am trying to get is this:
enter int: 1
*
enter int: 5
*
**
***
****
*****
Re: nested loop structure
package test;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner input = new Scanner( System.in );
String line;
System.out.println("Please enter the total number of lines to output, as any integer greater than 0 and less than 71:");
line = input.next();
for(int x=0; x<new Integer(line); x++){
for(int y=0; y<=x; y++){
System.out.print("*");
}
System.out.println("");
}
}
}
hope this will work fine as per your requirement.
Re: nested loop structure
thank you copeg, you are right, i did have set as a single line
Re: nested loop structure
This is awesome, thank you!
Quote:
Originally Posted by
cs13
package test;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner input = new Scanner( System.in );
String line;
System.out.println("Please enter the total number of lines to output, as any integer greater than 0 and less than 71:");
line = input.next();
for(int x=0; x<new Integer(line); x++){
for(int y=0; y<=x; y++){
System.out.print("*");
}
System.out.println("");
}
}
}
hope this will work fine as per your requirement.
Re: nested loop structure
Re: nested loop structure
This is just my opinion but,
To his defense, I don't think this is "spoon feeding" or whatever you wanna call it. I wrote the code, just had a line wrong and he identified it. Its not like I posted the assignment and he did it for me. He just fixed a line.
Re: nested loop structure
It is spoon-feeding.
He posted a solution, which could have been done better, with no explanations on what he changed or why the code works in comparison.
He stripped the learning / researching process away from you.
Albeit it was a very simple problem, It's still very much regarded as spoon-feeding.