+ 1

Program to add an element at the beginning/end/middle operations on an array using generic classes

24th Dec 2020, 3:42 PM
Madagalam Ammu
5 Respuestas
+ 3
package com.company; class math{ int sum; public void setSum(int s) { this.sum = s; } public int getSum(){ return this.sum; } } public class Main { public static void main(String[] args) { int [] number =new int[10]; number [0]=1;//1st term number [1]=2; number [2]=3; number [3]=4; number [4]=5;//middle term number [5]=6; number [6]=7; number [7]=8; number [8]=9; number [9]=10;//last term System.out.printf("first term : %d\n" ,number[0] ); System.out.printf("middle term : %d\n",number[(number.length/2)-1]); System.out.printf("last term : %d\n",number.length-1); int firstTerm =number[0]; int middleTerm =number[(number.length/2)-1]; int lastTerm =number[number.length-1]; math math = new math(); math.setSum(firstTerm+middleTerm+lastTerm); System.out.printf("the sum of the first term , middle term and the last term is %d",math.getSum()); } }
30th Dec 2020, 2:09 PM
Sushant Lama
Sushant Lama - avatar
0
Output for this
9th Aug 2021, 9:40 AM
19CSE020 MADHUMITHA R
19CSE020 MADHUMITHA R - avatar
0
16
12th Mar 2022, 2:45 PM
LAILA SHREE. P
0
Give an output
14th Dec 2022, 12:37 PM
Sɪᴠᴀ . JD - Csᴇ
Sɪᴠᴀ . JD - Csᴇ - avatar
- 5
Try it .
30th Dec 2020, 2:31 PM
Sushant Lama
Sushant Lama - avatar