Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1.(Sorting three integer) Write a program that sort three integer. The integers

ID: 3621956 • Letter: 1

Question

1.(Sorting three integer) Write a program that sort three integer. The integers are entered from the input dialogs and sorted in variable num1, num2 and num 3 respectively the program sorts the number so that num1<= num2<= num3

2.(Checking a number) Write a program that prompts the user to enter an integer and checks whether the number is divisible by both 5 and 6 neither , or just one of them Here are some sample out puts10.30 and

10 is divisible by 5 or 6 but not both

30 is divisible by both 5 and 6

23 is not divisible by either 5 or 6

3.Write Algorithm and then a java program that prompts the user to input a number. The program should then output the number and a message saying whether the number is positive negative or zero

 

4. Write an algorithem that asks the user to enter one of the following country abbreviataion (UAE,KSA,HKJ, ARE orSY the algorithm should then display the name of the country that corresponds with abbreviation entered(United Arab Emirates, Kingdom of Saudi Arabin,Hashemite Kingdom of Joran,Arab Republic of Egypt or Arab Republic of Syria) Display an error massage if an abbreviataion other than is listed is enterd. Change the Algorithm Written into aJava peogram using JCreator.

Explanation / Answer

Part 1) simplist way, store your inputs into your 3 variables without checking for size then do a simple sort. if (num1 > num2) { temp = num1; num1=num2; num2=temp; } if (num2 > num3){ temp = num2; num2 = num3; num3 = temp; } you are now guarenteed that num3 is the largest, but 1 and 2 could be different, so compare those again if (num1 > num2) { temp = num1; num1=num2; num2=temp; } i just wrote a simple bubblesort that works for exactly 3 elements, might not be the best way but should work for you at this point, you will learn more/better sorts as you move on 2) use modulus (%) and check for remainder of 0. mod division gives you the remainder, example 23 / 5 = 4 with remainder of 3, modulus gives you the remainder if (X % 5 == 0) the number is divisible by 5 if (X % 6 == 0) the number is divisible by 6 3) simple comparison if(X >= 0){ number is positive } else{ number is negative } 4)Use Java string comparison function if(COUNTRY_VARIABLE_HERE.compareTo("UAE") else if if(COUNTRY_VARIABLE_HERE.compareTo("KSA") else if.... repeat for each abbreviation else{ country not found }