Beauty of programming _ 001 write a function and return the result of division of all elements in an array by the first element

Source: Internet
Author: User
// Write a function and return the public class test {public static void main (string [] ARGs) result of division of all elements in an array by the first element) {int [] arr1 = {0, 1, 3, 6, 7, 9, 2, 33, 22, 11}; int [] arr2 = {2, 1, 3, 6, 7, 9, 2, 33, 22, 11}; For (int n: arr1) {system. out. print (n + "");} system. out. println (); For (int n: arr2) {system. out. print (n + "");} system. out. println ("\ n after the first number in the array:"); divisor (arr1); divisor (arr2); For (int n: arr1) {system. out. print (n + "");} system. out. println (); For (int n: arr2) {system. out. print (n + "") ;}} static void divisor (INT [] ARR) {If (ARR [0] = 0) {system. out. println ("arr [0] cannot be 0. ");} else {for (INT I = 1, Leng = arr. length-1; I <Leng; I ++) {arr [I] = arr [I]/ARR [0] ;}}}

Output result:

 
0 1 3 6 7 9 2 33 22 11 2 1 3 6 7 9 2 33 22 11 after removing the first number in the array: arr [0] cannot be 0.0 1 3 6 7 9 2 33 22 11 2 0 1 3 3 4 1 11 11

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.