Write a Java Program to do following String manipulation
String address1 = " Mr.Jack,Door No 21,Mason Street,3rd Main Road,Velachery,Chennai,Pin-600113";
String address2 = " Ms Jill,Door No 53,Mason Street,3rd Main Road,Velachery,Chennai,Pin-600113";
String address2 = " Mr Holmes,Door No 13,Valmiki Street,32d Main Road,Saidapet,Chennai,Pin-600115";
String address1 = " Mr.Davinci,Door No 21,Mason Street,3rd Main Road,Velachery,Chennai,Pin-600113";
Expected Output
Answers
public class JavaExample {
public void calculate(int p, int t, double r, int n) {
double amount = p * Math.pow(1 + (r / n), n * t);
double cinterest = amount - p;
System.out.println("Compound Interest after " + t + " years: "+cinterest);
System.out.println("Amount after " + t + " years: "+amount);
}
public static void main(String args[]) {
JavaExample obj = new JavaExample();
obj.calculate(2000, 5, .08, 12);
}
}
public class Main
{
public static void main(String args[]){
String address1 = " Mr.Jack,Door No 21,Mason Street,3rd Main Road,Velachery,Chennai,Pin-600113";
String address2 = " Ms Jill,Door No 53,Mason Street,3rd Main Road,Velachery,Chennai,Pin-600113";
String address3 = " Mr Holmes,Door No 13,Valmiki Street,32d Main Road,Saidapet,Chennai,Pin-600115";
String address4 = " Mr.Davinci,Door No 21,Mason Street,3rd Main Road,Velachery,Chennai,Pin-600113";
String[] ans1= address1.split(",", 7);
String[] ans2= address2.split(",", 7);
String[] ans3=address3.split(",", 7);
String[] ans4=address4.split(",", 7);
String name1=ans1[0],name2=ans2[0],name3=ans3[0],name4=ans4[0];
System.out.println(name1);
System.out.println(name2);
System.out.println(name3);
System.out.println(name4);
String add1="",add2="",add3="",add4="";
for(int i=1;i<7;i++){
add1=add1+" "+ans1[i];
}
for(int i=1;i<7;i++){
add2=add2+" "+ans2[i];
}
for(int i=1;i<7;i++){
add3=add3+" "+ans3[i];
}
for(int i=1;i<7;i++){
add4=add4+" "+ans4[i];
}if(add1.equals(add2)){
System.out.println(add1+"and"+add2+"are duplicate");
}
if(add1.equals(add3)){
System.out.println(add1+"and"+add3+"are duplicate");
}
if(add1.equals(add4)){
System.out.println(add1+"and"+add4+"are duplicate");
}
if(add2.equals(add3)){
System.out.println(add2+"and"+add3+"are duplicate");
}
if(add2.equals(add4)){
System.out.println(add2+"and"+add4+"are duplicate");
}
if(add3.equals(add4)){
System.out.println(add3+"and"+add4+"are duplicate");
}
if(address1.contains("Mason Street")){
System.out.println(add1);
}
if(address2.contains("Mason Street")){
System.out.println(add2);
}
if(address3.contains("Mason Street")){
System.out.println(add3);
}
if(address4.contains("Mason Street")){
System.out.println(add4);
}
if(address1.contains("Pin")){
System.out.println("Address1 has pincode");
}
if(address2.contains("Pin")){
System.out.println("Address2 has pincode");
}
if(address3.contains("Pin")){
System.out.println("Address3 has pincode");
}
if(address4.contains("Pin")){
System.out.println("Address4 has pincode");
}
}
}