Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
boundary vs core
import java.util.*; class Rextester { public static void main(String args[]) { Scanner sc=new Scanner(System.in); System.out.println("enter the number of rows and columns"); int r=sc.nextInt(); int c=sc.nextInt(); System.out.println("enter 1 for sum of boundary elements and 2 for sum of core elements"); int ch=sc.nextInt(); int arr[][]=new int[r][c]; int i,j,cr=0,bd=0; for(i=0; i<r; i++) { for(j=0; j<c; j++) { System.out.println("Enter a number"); arr[i][j]=sc.nextInt(); } } for(i=0; i<r; i++) { for(j=0; j<c; j++) { System.out.print(arr[i][j]+" "); } System.out.println(); } for(i=0; i<r; i++) { for(j=0; j<c; j++) { if((i>0 && i<(r-1)) && (j!=0 && (j!=c-1))) { cr+=arr[i][j]; } else { bd+=arr[i][j]; } } } if(ch==1) System.out.println("Sum of boundary elements is equal to "+bd); else System.out.println("Sum of core elemnts is equal to "+cr); } }
run
|
edit
|
history
|
help
0
LinearSearch
A.K.JAVA_EXPERIENCE_1
Day 1
Le saviez-vous ?
LRU cache - Simple solution (costly)
ChangePI
HelloWorld2
binary square root
JAVA # Boşluklu bir metinde kaç adet boşluk var
OBF-7 3