Answer to Question #286995 in Java | JSP | JSF for Sameeksha

Question #286995

The placement session has begun in a college. There is N number of students standing outside an interview room in a line. It is given that the person who goes first has higher chances of selection.






Each student has a number associated with them representing their problem-solving capability. The higher the capability the higher the chances of selection. Now every student wants to know the number of students ahead of him with higher problem-solving capability

1
Expert's answer
2022-01-12T08:47:52-0500


import java.util.Scanner;


public class App {


	/**
	 * The start point of the program
	 * 
	 * @param args
	 * 
	 */
	public static void main(String[] args) {
		Scanner keyBoard = new Scanner(System.in);
		int n, counter, i, j;
		System.out.print("Enter number of students: ");
		n = keyBoard.nextInt();
		int[] students = new int[n];


		System.out.print("Enter numbers: ");
		for (i = 0; i < n; i++) {
			students[i] = keyBoard.nextInt();
		}


		for (i = 0; i < n; i++) {
			counter = 0;
			for (j = 0; j < i; j++) {
				if (students[j] > students[i]) {
					counter += 1;
				}
			}
			System.out.printf("%d ", counter);
		}


		keyBoard.close();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog