Write two different password creation functions, password1() and password2(), ea
ID: 3880828 • Letter: W
Question
Write two different password creation functions, password1() and password2(), each of which has 3 arguments, intended to be 2 strings s1 and s2, and in the third position a number n.
Function password1 will return a string consisting of the two strings separated by an underscore character. Function password2 will return a string consisting of the (characters of) the number n followed by s1 followed by s2 followed by the (characters of) n.
Hint: To convert a number n to a string use the function str(). So, for example, str(2 + 3) will return '5'
So if your functions work correctly you would have:
Explanation / Answer
Here I created a class called Password having the methods password1 and password2 and in the main class I am calling the methods.
Note: This code is compiled and run successfully
class Password{
public void password1(String a, String b, int n ){
System.out.println(a + "_" + b );
}
public void password2(String c , String d , int m ){
String num = Integer.toString(m);
System.out.println(num+c+d+num);
}
}
public class Test{
public static void main(String []args){
Password pass = new Password();
pass.password1("yellow","Daisy",6);
pass.password2("yellow","Daisy",6);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.