Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class L06CarManufacturerQuiz
  4. {
  5.  
  6. public static void main(String[] args)
  7. {
  8.  
  9. Scanner iKeyboard = new Scanner (System.in);
  10. Scanner szKeyboard = new Scanner (System.in);
  11. int iNumOfArray , i , iNum = 1;
  12. String[] szArray;
  13. String szchoice , temp;
  14.  
  15. do
  16. {
  17. System.out.print("How many car manufacturers can you think of? ");
  18. iNumOfArray = iKeyboard.nextInt();
  19.  
  20. szArray = new String[iNumOfArray];
  21.  
  22. for(i=0; i!=iNumOfArray; i++)
  23. {
  24. System.out.print("Enter the name of a car manufacturer. "+iNum+ " ");
  25. szArray [i] = szKeyboard.nextLine();
  26. iNum++;
  27. }
  28.  
  29. System.out.println("You have entered the following car manufacturers: ");
  30.  
  31. iNum = 1;
  32. for(i=0; i!=iNumOfArray; i++)
  33. {
  34.  
  35. System.out.println(iNum+". "+szArray[i]);
  36. iNum++;
  37. }
  38.  
  39. for ( i = 0; i < iNumOfArray; i++)
  40. {
  41. for (int j = i + 1; j < iNumOfArray; j++)
  42. {
  43. if (szArray[i].compareTo(szArray[j])>0)
  44. {
  45. temp = szArray[i];
  46. szArray[i] = szArray[j];
  47. szArray[j] = temp;
  48. }
  49. }
  50. }
  51. System.out.print("Names in Sorted Order:");
  52. for ( i = 0; i < iNumOfArray - 1; i++)
  53. {
  54. System.out.print(szArray[i] + ",");
  55. }
  56. System.out.print(szArray[iNumOfArray - 1]);
  57.  
  58. System.out.println("\nWould you like another attempt, Y or N? ");
  59. szchoice= szKeyboard.nextLine();
  60.  
  61. }while(!(szchoice.equals("Y") ||szchoice.equals("y")));
  62. }
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement