Untitled
unknown
plain_text
a year ago
996 B
4
Indexable
import java.util.*; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int arr[] = {10,20,30,40,50,60}; int max = Integer.MIN_VALUE; int min = Integer.MAX_VALUE; for(int i = 0; i<arr.length; i++){ max = Math.max(max, arr[i]); min = Math.min(min, arr[i]); } System.out.println(max); System.out.println(min); } } Q2} public class Solution { public static void main(String[] args) { int arr[][] = {{1,2,3,4},{5,6,7,8}}; int sum = 0; for(int i=0; i<arr.length;i++){ for(int j=0; j<arr[0].length; j++){ sum+=arr[i][j]; } } System.out.println("Sum of all elements in the 2D array is: "+sum); } } Q3} import java.util.*; public class Solution { public static void main(String[] args) { String str[] = {"mango", "apple", "strawberry","banana"}; for(int i=0; i<str.length; i++){ for(int j=i+1; j<str.length; j++){ if(str[i].compareTo(str[j])>0){ //str[i] is Greater than str[j] //swap
Editor is loading...
Leave a Comment