Professional Documents
Culture Documents
Assignment-2
CODE:
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String str = "harsha vardhan is my name";
String word;
int count1 =0;
System.out.println("Enter the word you want to find count of : ");
word = sc.nextLine();
String temp[] = str.split(" ");
int count = 0;
for (int i = 0; i < temp.length; i++) {
if (word.equals(temp[i]))
count++;
}
System.out.println("The string is: " + str);
System.out.println("The word " + word + " occurs " + count + "
times in the above string");
Code:
import java.util.*;
for(int i=0;i<5;i++){
System.out.println(" ");
for(int j=0;j<6;j++){
a[i][j]=sc.nextInt();
for(int i=0;i<5;i++){
for(int j=0;j<6;j++){
System.out.print(a[i][j]+" ");
}
System.out.println("");
if (a[i][j]>max)
max = a[i][j];
temp[i] = max;
i++;
Arrays.sort(temp);
for (int i = 0; i < 5; i++)
if(a[i][j]==temp[5-1])
else if(a[i][j]==temp[5-2])
else if(a[i][j]==temp[5-3])
if (a[i][j]<min)
min = a[i][j];
temp1[i] = min;
i++;
Arrays.sort(temp1);
if(a[i][j]==temp1[0])
{
System.out.println("First coldest day is in DAY
"+(i+1)+" and "+(j+6)+"AM");
else if(a[i][j]==temp1[1])
else if(a[i][j]==temp1[2])
sum += a[i][j];
avg[i] = sum/6;
//Arrays.sort(avg);
b[i][j] = avg[i];
{
for (int j =0 ; j< 1 ; j++)
System.out.println(b[i][j]);
Arrays.sort(avg);
if (b[i][j]==avg[5-1])
else if (b[i][j]==avg[5-2])
{
System.out.println("Second Avg hottest
temperature is in DAY "+(i+1));
else if(b[i][j]==avg[5-3])
Code screenshot
Code output: