
Hi Sir,
please send me the code for the following progrems...
1) all sets are integer type: input: set1={10,20,30,40} set2={15,25,35}
output:
union={10,15,20,25,30,35,40}
2) input: "Hi what are you doing"
output: "doing you are what Hi"

1)
import java.util.*;
public class SetsUnion{
public static void main(String[] args){
Set a = new HashSet();
a.add(10);
a.add(20);
a.add(30);
a.add(40);
Set b = new HashSet();
b.add(15);
b.add(25);
b.add(35);
Set s=new HashSet(a);
s.addAll(b);
ArrayList l=new ArrayList(s);
System.out.println("Set A: "+a);
System.out.println("Set B: "+b);
System.out.println();
Collections.sort(l);
System.out.println("A U B is: "+l);
}
}
2)
import java.util.*;
class ReverseWords{
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.print("Enter String: ");
String st=input.nextLine();
StringBuffer buffer=new StringBuffer();
String str[]=st.split(" ");
for(int i=str.length-1;i>=0;i--){
buffer.append(str[i]);
buffer.append(" ");
}
System.out.println(buffer.toString());
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.