+ 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"); } } }

14th Mar 2020, 6:12 AM
Akash Sharma
Akash Sharma - avatar
2 ответов
14th Mar 2020, 6:23 AM
Oma Falk
Oma Falk - avatar
+ 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.
14th Mar 2020, 6:42 AM
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~ - avatar