+ 2
What is the mistake in the program.
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String a = scan.nextLine(); int b = scan.nextInt(); if(a.isEmpty()){ System.out.println("Pls. Enter month of your bith");}else if(b.isEmpty()){ System.out.println("Pls. Enter your birth date"); }else{ System.out.println("Pls. Enter your month and date of birth respectively"); } } }
2 ответов
+ 2
Akash isEmpty() method is only for string types.
It is invalid to use this method with Integer variables.
However you can overcome this problem by changing an int to a equivalent string variable and compare it through isEmpty() method.
Like:Integer.toString(b).isEmpty(),like oma has mentioned you can share your code through sharing your link directly from code playground rather than in post.