| Previous | Home | Next |
Example
//Example for String Conversion And String Concatenation
package r4r.co.in;
import javax.swing.*;
public class StringDemo {
public static void main(String[] args) {
String name = JOptionPane.showInputDialog("Enter your name?");
//Enter first input(name)
String input = JOptionPane.showInputDialog("Enter your Age?");
//Enter second input(Age)
int age = Integer.parseInt(input);
//String Conversion string to integer value
// String Concatenation and display output on console.
System.out.println("Hello,Dear " + name + ". Next year, you'll be " + (age + 1));
//Terminates the currently running Java Virtual Machine, and return abnormal termination.
System.exit(0);
}
}
Output:
Hello,Dear Rajesh. Next year, you'll be 25.
//Login Application in String
package r4r.co.in;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class loginApplication {
public static void main(String[] args) throws IOException {
String s1 = new String("r4r@techsoft.com");
String s2 = new String("r4r");
System.out.println("Username:" + s1.toString() + "\nLength: " + s1.length());
//Used String Concatenation
System.out.println("Password:" + s2.toString());
BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in));
//BufferedReader class is used for input the value
System.out.println("Enter your Username:");
String st1 = br1.readLine();
System.out.println("Your username:" + st1.toString());
BufferedReader br2 = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter your Password:");
String st2 = br2.readLine();
System.out.println("Your username:" + st2.toString());
try {
if (s1.equals(st1) && s2.equals(st2)) { //String Comparison match
System.out.println("Authentication persion:Welcome to R4R");
} else {
System.out.println("Invalid Username And Password");
}
} catch (Exception e) {
System.out.print(e);
}
}
}
output:
Username:r4r@techsoft.com Length: 16 //length can be estimated by using length() method Password:r4r Enter your Username: r4r@techsoft.com //Enter name using BufferReader Your username:r4r@techsoft.com Enter your Password: r4r Your username:r4r Authentication persion:Welcome to R4R
| Previous | Home | Next |