Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Q3_reverseSortDemo
- public class Q3_ReverseSortDemo {
- public static void main(String[] args){
- char[] unorderedLetters;
- unorderedLetters = new char[]{'b', 'm', 'z', 'a', 'u'};
- reverseSort(unorderedLetters);
- for (int i = 0 ; i < unorderedLetters.length; i++ )
- System.out.print(unorderedLetters[i]);
- }
- //method that sorts a char valuesay into its reverse alphabetical order
- public static void reverseSort(char[] values){
- //your code here
- int n = values.length;
- char temp;
- for(int i=0; i < n; i++){
- for(int j=1; j < (n-i); j++){
- if(values[j-1] > values[j]){
- //swapping elements
- temp = values[j-1];
- values[j-1] = values[j];
- values[j] = temp;
- }
- }
- }
- }
- }
- //Q6
- import java.util.Scanner;
- public class Q6{
- public static void main(String[] args){
- //your code here
- System.out.print("Input 10 students grades: ");
- Scanner scanName = new Scanner(System.in);
- double[] myDouble = scanName.nextDouble();
- System.out.print(calculateAverage(myDouble));
- System.out.print(calculateMedian(myDouble));
- System.out.print(calculateNumberFailed(myDouble));
- System.out.print(calculateNumberPassed(myDouble));
- }
- public static double calculateAverage(double[] notes){
- //your code here
- double result;
- double total = 0;
- for(int i = 0; i <= notes.length-1; i++){
- total = total + notes[i];
- }
- result = total/notes.length;
- return result;
- }
- public static double calculateMedian(double[] notes){
- //your code here
- double median;
- double medianPosition=notes.length/2;
- median = notes[medianPosition];
- return median;
- }
- public static int calculateNumberFailed(double[] notes){
- //your code here
- double failed = 0;
- for(int i = 0; i <= notes.length-1; i++){
- if(notes[i]<=50){
- failed=failed+1;
- }
- return failed;
- }
- }
- public static int calculateNumberPassed(double[] notes){
- //your code here
- double passed = 0;
- for(int i = 0; i <= notes.length-1; i++){
- if(notes[i]>=50){
- passed=passed+1;
- }
- return passed;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement