-
loopinggggggggggg
Hello can someone please tell me why my compiler is saying that the break is outside of the loop?
public static String editItemNumber()
{
Scanner input = new Scanner(System.in);
System.out.println("Enter Item Number: ");
String item = input.nextLine();
int itemlength= item.length();
do
{
}
while (itemlength!=5);
{
System.out.print("**ERROR1** - Item Number must be five characters ");
if(itemlength!= 5)break;
}
}
}
-
Re: loopinggggggggggg
Why is this needed?
Code:
if(itemlength!= 5)break
When this loop continues when itemlength!=5:
Code:
do
{
}
while (itemlength!=5);
Try something like this instead:
Code:
public static String editItemNumber()
{
Scanner input = new Scanner(System.in);
String item;
int itemlength;
System.out.println("Enter Item Number: ");
do
{
item = input.nextLine();
itemlength= item.length();
if (itemlength!=5) System.out.print("**ERROR1** - Item Number must be five characters ");
}
while (itemlength!=5);
}
}
Do you want it to repeat until the string input is 5 characters long? If so i believe the above code should do the trick.
Hope this helps,
Regards Serb.