Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class L06CarManufacturerQuiz
- {
- public static void main(String[] args)
- {
- Scanner iKeyboard = new Scanner (System.in);
- Scanner szKeyboard = new Scanner (System.in);
- int iNumOfArray , i , iNum = 1;
- String[] szArray;
- String szchoice , temp;
- do
- {
- System.out.print("How many car manufacturers can you think of? ");
- iNumOfArray = iKeyboard.nextInt();
- szArray = new String[iNumOfArray];
- for(i=0; i!=iNumOfArray; i++)
- {
- System.out.print("Enter the name of a car manufacturer. "+iNum+ " ");
- szArray [i] = szKeyboard.nextLine();
- iNum++;
- }
- System.out.println("You have entered the following car manufacturers: ");
- iNum = 1;
- for(i=0; i!=iNumOfArray; i++)
- {
- System.out.println(iNum+". "+szArray[i]);
- iNum++;
- }
- for ( i = 0; i < iNumOfArray; i++)
- {
- for (int j = i + 1; j < iNumOfArray; j++)
- {
- if (szArray[i].compareTo(szArray[j])>0)
- {
- temp = szArray[i];
- szArray[i] = szArray[j];
- szArray[j] = temp;
- }
- }
- }
- System.out.print("Names in Sorted Order:");
- for ( i = 0; i < iNumOfArray - 1; i++)
- {
- System.out.print(szArray[i] + ",");
- }
- System.out.print(szArray[iNumOfArray - 1]);
- System.out.println("\nWould you like another attempt, Y or N? ");
- szchoice= szKeyboard.nextLine();
- }while(!(szchoice.equals("Y") ||szchoice.equals("y")));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement