Big Data Third day job

Source: Internet
Author: User

1. Define a function function that dynamically extracts the maximum value of an element in int[]. public class Main {/** * defines a function that functions as the maximum value for dynamically extracting elements in int[]. */public static void Main (string[] args) {//definition array int[] nums = new int[5];//initialize array for (int i= 0;i<5;i++) {nums[i] = i;} int max = Getmax (nums); System.out.println ("the largest value in the array is:" +max);} /** * Gets the largest element in an integer array */public static int Getmax (int[] nums) {int tmp = 0;for (int i = 0;i<nums.length;i++) {if (nums[i]> TMP) {tmp = i;}} return tmp;}}
2. Define a function to query the position of the first occurrence of the specified element from the array. public class Main {/** * defines a function that queries the location of the first occurrence of the specified element from the array. */public static void Main (string[] args) {char[] STRs = {' h ', ' e ', ' l ', ' l ', ' o '};char c = ' e '; int index = INDEXOF (STRS,C); System.out.println ("character" +c+ "the first occurrence of the position is:" +index);} public static int indexOf (char[] Strs,char c) {for (int i =0;i<strs.length;i++) {if (strs[i]==c) {return i;} Else{system.out.println ("No corresponding element found");}} return-1;}}

3. Define the function, complete the bubble sort, and sink the large number.

The public class Main {/** * Defines the function, completes the bubbling sort, and sinks the large number. */public static void Main (string[] args) {int[] nums = new int[5];//Initialize Array (descending) for (int i=4,n=0; i>=0; I--, n++) {Nums[n] = i;} System.out.println ("Pre-sort");p rintnums (nums);//Sort Nums=order (nums); System.out.println ("Post-order");p rintnums (nums);} public static int[] Order (int[] nums) {for (int. i=0;i<nums.length;i++) {for (int j=0;j<nums.length-(i+1); j + +) {if ( Nums[j]>nums[j+1]) {int tmp;tmp=nums[j];nums[j]=nums[j+1];nums[j+1]=tmp;}}} return nums;} public static void Printnums (int[] nums) {for (int J =0;j<5;j++) {System.out.print (nums[j]);} System.out.println ();}}

4. Binary Search

public class Main {/* * binary lookup */public static void Main (string[] args) {int[]nums = new int[10];for (int i=0;i<10;i++) {nu Ms[i] =i;} Find (nums,10,0,nums.length-1);} public static void Find (int[] nums,int n,int begin,int end) {int mid = (Nums[begin]+nums[end])/2;if (mid = = N) {System.out.pr Intln ("Found");} if (n>mid) {begin = Mid;find (nums,n,begin,end);} if (n<mid) {end = Mid;find (Nums,n,begin,end);}}}

5. Don't understand test instructions?

6. Define a function that implements the transpose of the matrix. arr[i][j] = = arr[j][i];//the precondition is affirmative.

public class main {/** *  defines a function that implements the transpose of the matrix. arr[i][ j] == arr[j][i];//precondition is affirmative  */public static void main (String[] args)  { Int[][] nums= new int[3][3];int num = 0;for (int i = 0; i< 3; i++) {for (int j =0 ;j<3;j++) {nums[i][j] = num;num++;}} System.out.println ("Pre-conversion");p rintnums (nums); Nums=reverse (nums); System.out.println ("post-conversion");p rintnums (nums);} Public static int[][] reverse (int[][]nums) {int[][] nums2= new int[3][3];for (int  i=0;i<3;i++) {for (int j=0;j<3;j++) {nums2[i][j] = nums[j][i];}} RETURN&NBSP;NUMS2;} Public static void printnums (int[][]nums) {for (int i = 0; i<3; i++) { for (int j =0 ;j<3;j++) {System.out.print (nums[i][j]);} System.out.println ();}}} 

7. Traverse three-dimensional groups and output each layer of the three-dimensional array horizontally.

public class Main {/** * iterates through three-dimensional groups, outputting each layer of a three-dimensional array */public static void Main (string[] args) {int[][][] nums = new Int[3][3][3]; int num = 0;for (int i=0;i<3;i++) {for (int. j=0;j<3;j++) {for (int k=0;k<3;k++) {Nums[i][j][k] = num++;}}} for (int i=0;i<3;i++) {for (int. j=0;j<3;j++) {for (int k=0;k<3;k++) {System.out.print (nums[i][j][k]);} System.out.println ();} System.out.println ();}}}

8. Define a class: Dog has a name of color age Cry ();

public class Dog {private String color;private int age;public void Cry () {System.out.println ("Wang Woo");} public int getage () {return age;} public void Setage (int.) {this.age = age;} Public String GetColor () {return color;} public void SetColor (String color) {this.color = color;}}

9. Describe the heap area, stack area, when overflow, how to solve.

A: Heap is the area where the object is stored in the virtual machine, the stack is an advanced data structure, there is a method stack in the Java Virtual machine, the stack of the method frame, a program must have at least one stack as the main function stack.

If the new object in the constructor will have a stack overflow, to prevent the stack overflow will be careful to write code, do not appear the scene of the creation of the dead loop, the use of resources to be released in a timely manner.

10.oop

A: OOP is object-oriented programming, which encapsulates the data as a class's properties, and the object-oriented advantage is that it is highly scalable and does not appear "two times wheel-making".

Big Data Third day job

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.