import java.util.Scanner;
public class DisplayBox2 {
public static void box (int length, int width){
Scanner input = new Scanner (System.in) ;
String Answer;
System.out.println("Do you want to use a special character to use to display the box ?");
Answer = input.nextLine();
if (Answer == "Yes"){
System.out.println("Please enter the character that you would like to display the box");
int Char = input.nextInt();
for (int i = 0; i < length; i++) {
for (int j = 0; j < width; j++) {
System.out.print(Char +" ");
}
System.out.println("");
}
}
if (Answer == "No"){
for (int i = 0; i < length; i++) {
for (int j = 0; j < width; j++) {
System.out.print(" *");
}
System.out.println("");
}
}
input.close();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner (System.in);
int length, width ;
System.out.println ("Please enter the length of the box");
length = input.nextInt();
System.out.println (" Please enter the width of the box");
width = input.nextInt();
input.close();
box (length, width);
}
}
i dont understand what the error is in my code. can anyone please help
Please enter the length of the box
5 Please enter the width of the box
5 Do you want to use a special character to use to display the box ?
Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Unknown Source)
at methods.DisplayBox2.box(DisplayBox2.java:14)
at methods.DisplayBox2.main(DisplayBox2.java:56)