SeperateAndMerge.java 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import java.util.Iterator;
  2. import java.util.Scanner;
  3. public class SeperateAndMerge {
  4. /**
  5. * @param args
  6. */
  7. public static void main(String[] args) {
  8. LList<Integer> listInt = new LList<Integer>();
  9. LList<Float> listFloat = new LList<Float>();
  10. Scanner in = new Scanner(System.in);
  11. while (in.hasNext())
  12. {
  13. if (in.hasNextInt())
  14. {
  15. listInt.add(in.nextInt());
  16. }
  17. else if (in.hasNextFloat())
  18. {
  19. listFloat.add(in.nextFloat());
  20. }
  21. else
  22. {
  23. in.next();
  24. }
  25. }
  26. in.close();
  27. System.out.print("Inputted values:");
  28. Iterator<Integer> intIter = listInt.iterator();
  29. Iterator<Float> fltIter = listFloat.iterator();
  30. while (intIter.hasNext() && fltIter.hasNext())
  31. {
  32. System.out.print(" ");
  33. System.out.print(intIter.next());
  34. System.out.print(" ");
  35. System.out.print(fltIter.next());
  36. }
  37. while (intIter.hasNext())
  38. {
  39. System.out.print(" ");
  40. System.out.print(intIter.next());
  41. }
  42. while (fltIter.hasNext())
  43. {
  44. System.out.print(" ");
  45. System.out.print(fltIter.next());
  46. }
  47. System.out.println();
  48. }
  49. }