+ 1
How to check if a number ends with 2?
5 Réponses
+ 4
if(x%10==2)
ends with 2
else
doesnt end with 2
+ 1
you can use Strings ..
so you input the number as string and then cheack if the last number is equal to 2 this code will be thing like this
Scanner in =new Scanner (System.in);
String n=in.next();
if(n.charAt(n.length()-1)=='2')
System.out.println("yes");
else
System.out.println("no");
+ 1
welcome
0
thanks a lot👍
0
thanks again