Practice set chapter 6

 package com.company;

import java.util.Scanner;
public class CWH_Practice_29 {
public static void main(String[] args) {
// float [] price= {23.4f,45.09f,44.56f,33.66f,54.22f};
// float sum=0.0f;
// for(int i=0;i<5;i++){
//
// sum= sum+price[i];
//
// }
// System.out.println("The sum of given array is "+sum);

// Question 2
//Scanner sc=new Scanner(System.in);
// System.out.println("Enter the number");
// int n= sc.nextInt();
// int [] arr={2,3,4,5,6,7,};
// boolean isInArray=false;
// System.out.print("Array is:" );
// for(int element:arr){
// System.out.print(element);
// System.out.print(" ");
// }
//
// System.out.println("");
// for(int j=0;j<6;j++){
// if(arr[j]==n){
// isInArray=true;
// break;
// }
// }
//
// if(isInArray){
// System.out.println("Matched");
// }
//else{
// System.out.println("Not matched");
// }

// Question 3
// float average=0.0f;
// float sum=0.0f;
//float [] marks= {56.5f,55,44,46.5f,98,99,100,};
// System.out.println("The marks of student are: ");
// for(float element: marks){
// System.out.println(element);
// }
//
// for( float element:marks){
// sum=sum+element;
// }
// average=sum/marks.length;
// System.out.println("Sum is "+sum);
// System.out.println("Average is "+average);
// System.out.printf("%8.2f",average);

// Question 4

// int [][]age1={{1,2,3},
// {2,5,6}};
// int [][]age2= {{2,4,4,},
// {3,3,4}};
//
// int [][]resArray={{0,0,0},
// {0,0,0}};
//
// for(int i=0;i<age1.length;i++){
// for(int j=0;j<age1[i].length;j++){
//
// resArray[i][j]= age1[i][j]+age2[i][j];
// System.out.print(resArray[i][j]+" ");
// }
// System.out.println("");
// }

// Question 5 method 1

// int [] array= {1,2,3,4,5};
// int [] ar={0,0,0,0,0};
// for(int i= 4;i>=0;i--){
// ar[array.length-1-i]=array[i];
// System.out.print(ar[array.length-1-i]);
// System.out.print(" ");

// Method 2 by CWH
// int [] arr= {56,65,72,2,3,4};
// int a= Math.floorDiv(arr.length,2);
// int temp;
//
// for(int i=0;i<a;i++){
// temp=arr[i];
// arr[i]=arr[arr.length-i-1];
// arr[arr.length-1-i]=temp;
//
//
// }
// for (int element:arr){
// System.out.print(element+" ");
// }
// Question 6

// int [] a= {234,3,4,555,66,1999,0,21,22};
// int max=0;
//
// for(int e:a){
// if(e>max){
// max=e;
// }
//
// }
// System.out.println("Maximum value is: "+max);
//Question 7

// int [] a= {234,3,4,555,66,1999,10,21,22};
// int min=Integer.MAX_VALUE;
//
// for(int e:a){
// if(e<min){
// min=e;
// }
//
// }
// System.out.println("Minimum value is: "+min);
//

// Question 8
boolean isSorted= true;
int [] a={1,2,3,67,89};
for(int i=0;i<a.length-1;i++){
if(a[i]>a[i+1]){
isSorted=false;
break;
}
}if(isSorted)
System.out.println(" Sorted");
else{
System.out.println(" Not Sorted");
}

}
}

Comments