I am new to Java, and I need help with this code that keeps cutting short after the "do-while" loop. As in, the program ends after it is compiled and I enter a positive integer (its what satisfies the loop). I even copied the code into another file and it compiled fine. I have been scratching my head for an hour and cannot figure it out.
import java.util.Scanner;
public class BarakLoops
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
//Get positive values from user; declare variable(s)
int number=-1;
//Operate do while loop for positive int
while (number <= 0) {
System.out.println("Please enter a positive integer:");
number = input.nextInt();
}
//Ask user for name and loop
String name = input.nextLine();
int length = name.length();
for(int i=0;i<=length;i++) {
System.out.println(name);
}
input.close();
}
}
Compiler: DrJava - Eclipse 4.5 I have not found this answer elsewhere, please take your time to read.