-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordValidator.java
More file actions
41 lines (38 loc) · 1.06 KB
/
PasswordValidator.java
File metadata and controls
41 lines (38 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
*
* @author Mudassar
*/
/*
11. Implement a program to accomplish the following task using String/StringBuffer class:
i. Accept a password from user.
ii. Check if password is correct, then display Good else display Incorrect Password
iii. Append the password with the string Welcome to Java!!!
iv. Display the password in reverse order
*/
import java.util.Scanner;
public class PasswordValidator {
public static void main(String[] args)
{
String s;
StringBuffer sb;
Scanner sc=new Scanner(System.in);
System.out.println("Enter password:");
s=sc.nextLine();
sb=new StringBuffer(s);
if (sb.equals("supersecert"))
{
System.out.println("Good");
sb.append("Welcome to java!!!");
System.out.println(sb);
sb.reverse();
System.out.println(sb);
sb.replace(0,10,"***");
sb.reverse();
System.out.println(sb);
}
else
{
System.out.println("Incorrect password");
}
}
}