Junior Coders Academy is a unique learning Centre that offers a creative and inspiring collaborative environment for building coding skills to students of Grades 1 to 12.
Williams, the proprietor of the Academy and the mentor for the students started his first session of the day with the interesting programming concept of using Functions. Post an interactive session of learning through design, Williams gave the students a small self-activity to verify from two integer numbers A and B, if B corresponds to the last digit/digits of A. Williams wanted you to write the program for evaluating the students’ codes.
Hence create a class named EvaluateCodes with the following method.
Method Name | Description |
int findValue(String,String) | This method should return 1 if the second number B is the last digits of A, else return 0. |
Create a driver class called Main. In the Main method, obtain input from the user in the console and display “Yes” if the second number B is the last digits of A, else Print “No” by calling the findValue method present in the EvaluateCodes class.
[Note: Strictly adhere to the Object Oriented Specifications given in the problem statement.
All class names, attribute names and method names should be the same as specified in the problem statement. Create separate classes in separate files.]
Input Format:
First line of the input contains the number A.
Second line of the input contains the number B.
Output Format:
Print “Yes”)without quotes) if the second number B is the last digits of A. Print “No”(without quotes) otherwise.
Refer sample input and output for formatting specifications.
Sample Input 1:
1234
1234
Sample Output 1:
Yes
Sample Input 2:
5434554
543
Sample Output 2:
No
Solution
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String a = sc.next();
String b = sc.next();
findValue(a,b);
}
public static void findValue(String a, String b) {
if(a.endsWith(b))
//sauravhathi
System.out.println("Yes");
else
System.out.println("No");
}
}
#include <iostream>
using namespace std;
void findValue(String a, String b) {
if(a.endsWith(b))
cout << "Yes" << endl;
//sauravhathi
else
cout << "No" << endl;
}
int main() {
String a, b;
cin >> a >> b;
findValue(a, b);
return 0;
}
def findValue(a,b):
a=a[::-1]
b=b[::-1]
#sauravhathi
if(a.find(b)==0):
print('Yes')
#sauravhathi
else:
print('No')
x=input()
y=input()
#sauravhathi
findValue(x,y)
Happy Learning – If you require any further information, feel free to contact me.