Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Roman Kungurov
- // Exercise 1
- public class Runner {
- String name;
- double[] results;
- public Runner(String name, double[] results) {
- this.name = name;
- this.results = results;
- }
- public double averageRun() {
- double avg=0;
- for(int i=0; i<results.length; i++) {
- avg += results[i];
- }
- return avg/results.length;
- }
- public int goodScores(Runner runner) {
- int count=0;
- double avg = this.averageRun();
- for(int i=0; i<runner.getResults().length; i++) {
- if(runner.getResults()[i] > avg)
- count++;
- }
- return count;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public double[] getResults() {
- return results;
- }
- public void setResults(double[] results) {
- this.results = results;
- }
- }
- // Exercise 2
- import java.util.Scanner;
- public class Party {
- static int[] boys = new int[200];
- static Scanner in = new Scanner(System.in);
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- voting();
- System.out.println("The party's king is the boy number" + kingOfParty());
- System.out.println(wanted() + " boys were wanted");
- System.out.println(notVoted() + " boys hadn't been voted at all");
- }
- public static int[] voting() {
- for (int i = 0; i < 180; i ++) {
- for(int v = 1; v <= 10; v++) {
- System.out.println("Enter boy's number " + v);
- int boyNumber = in.nextInt();
- boys[boyNumber] += (11-v);
- }
- System.out.println("Now is next girl's turn");
- }
- return boys;
- }
- public static int kingOfParty() {
- int max = boys[0];
- int k=0;
- for(int i=0; i<boys.length; i++) {
- if(max < boys[i]) {
- boys[i] = max;
- k = i;
- }
- }
- return k;
- }
- public static int wanted() {
- int avg=0, count=0;
- for(int i=0; i<boys.length; i++) {
- avg += boys[i];
- }
- avg /= boys.length;
- for(int i=0; i<boys.length; i++) {
- if(boys[i] > avg)
- count++;
- }
- return count;
- }
- public static int notVoted() {
- int count=0;
- for(int i=0; i<boys.length; i++) {
- if(boys[i] == 0)
- count++;
- }
- return count;
- }
- }
- // Exercise 3
- import java.util.Scanner;
- public class Arr {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- System.out.println("Please enter the array's length");
- int n = in.nextInt();
- int[] nums = new int[n];
- for(int i = 0; i < nums.length; i++) {
- System.out.println("Please enter the number");
- nums[i] = in.nextInt();
- }
- int max =0;
- for(int i = 2; i <= nums.length/2; i++) {
- if(lineChecking(nums,i) == 1) {
- max = i;
- }
- }
- if(max == 0)
- System.out.println("The array is not organized at all");
- else
- System.out.println("The array is organized in " + max + " level");
- }
- public static int arr(int[] arr, int i, int j) {
- for(i=i; i<j; i++) {
- if(!(arr[i] == arr[j]))
- return 0;
- }
- return 1;
- }
- public static int lineChecking(int[] arr, int m) {
- int n = arr.length;
- int j = n/m - 1;
- int i = 0, count = 0;
- for(int t=0; t<n/m; t++) {
- count += arr(arr, i, j);
- j += n/m;
- i += n/m;
- }
- if(count == n/m)
- return 1;
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement