W.A.P that take an array of int type of size 50 Fill this array by multiple of 9 print it.

LAB#3

Arrays  And Calender in  JAVA

 

  1. OBJECTIVE: 

W.A.P that take an array of int type of size 50 Fill  this array by multiple of 9 print it.

Input:

public class Lab3_Task1 {

public static void main(String[] args) {

// TODO Auto-generated method stub

int[] list = new int[50];

int m = 9;

 

for(int k = 0; k < list.length; k++){

list[k] = m;

System.out.println(list[k]);

m = m + 9;

}// end for loop

}

}

Output:

9

18

27

36

45

54

63

72

81

90

99

108

117

126

135

144

153

162

171

180

189

198

207

216

225

234

243

252

261

270

279

288

297

306

315

324

333

342

351

360

369

378

387

396

405

414

423

432

441

450

  1. OBJECTIVE

W.A.P that take a String array of size 10. Fill this array by user favorite  Chocolates Print it.

Input:

import java.util.Scanner;

public class Lab3_Task2 {

public static void main(String[] args) {

Scanner enter = new Scanner(System.in);

String[] chocolates = new String[10];

 

System.out.println(“Enter ten names of chocolates”);

for(int k = 0; k < chocolates.length; k++){

System.out.print(“Enter Name : “);

chocolates[k] = enter.nextLine();

}// end for loop

System.out.println(“\nYour Favourite Chocolates”);

for(int h = 0; h < chocolates.length; h++){

System.out.println((h+1)+”. “+chocolates[h]);

}// end for loop

enter.close();}}

Output:

Enter ten names of chocolates

Enter Name : bubbly

Enter Name : bob

Enter Name : brto

Enter Name : frotu

Enter Name : jubli

Enter Name : zorain

Enter Name : jure

Enter Name : forr

Enter Name : roto

Enter Name : zobo

Your Favourite Chocolates

  1. bubbly
  2. bob
  3. brto
  4. frotu
  5. jubli
  6. zorain
  7. jure
  8. forr
  9. roto
  10. zobo
  11. OBJECTIVE: 

Implement all the method of Calender class

Input:

import java.util.Calendar;

import java.util.GregorianCalendar;

public class Lab3_Task3 {

public static void main(String[] args) {

// TODO Auto-generated method stub

Calendar c = new GregorianCalendar();

System.out.println(“HOUR : “+c.get(Calendar.HOUR));

System.out.println(“MINUTE : “+c.get(Calendar.MINUTE));

System.out.println(“SECONDS : “+c.get(Calendar.SECOND));

System.out.println(“YEAR : “+c.get(Calendar.YEAR));

System.out.println(“DAY OF MONTH : “+c.get(Calendar.DAY_OF_MONTH));

System.out.println(“DAY OF YEAR : “+c.get(Calendar.DAY_OF_YEAR));

System.out.println(“WEEK OF MONTH : “+c.get(Calendar.WEEK_OF_MONTH));

System.out.println(“WEEK OF YEAR : “+c.get(Calendar.WEEK_OF_YEAR));

}}

Output:

HOUR : 10

MINUTE : 36

SECONDS : 35

YEAR : 2017

DAY OF MONTH : 13

DAY OF YEAR : 44

WEEK OF MONTH : 3

WEEK OF YEAR : 7

  1. OBJECTIVE: 

Implement the Algorithem if finding Minimum & Maximum number in Array.

Input:

public class Lab3_Task4 {

public static void main(String[] args) {

// TODO Auto-generated method stub

int[] list = {10,256,10,455,24,62,6,89,70,1000};

int max = list[0];

int min = list[0];

for(int k = 1; k < list.length; k++){

if(list[0] > list[k]){

max = list[0];

list[0] = max;

}// end if

else {

max = list[k];

list[0] = max;

}// end else

}// end for loop

System.out.println(“Maximum Number is “+max);

list[0] = min;

for(int h = 1; h < list.length; h++){

if(list[0] < list[h]){

min = list[0];

list[0] = min;

}// end if

else {

min = list[h];

list[0] = min;

}// end else

}// end for loop

System.out.println(“Minimum Number is “+min);

}}

Output:

Maximum Number is 1000

Minimum Number is 6

 

Home Task:

1)    OBJECTIVE: 

W.A.P that Splits the existing Array by acoking uses from where  to Split.

Input:

import java.util.Scanner;

public class Home_Task_2 {

public static void main(String[] args) {

Scanner enter = new Scanner(System.in);

int[] numbers = {10,20,30,40,50,60,70,80,90,100};

for(int k = 0; k < numbers.length; k++){

System.out.println(“At Position[“+k+”] = “+numbers[k]);

}

System.out.print(“Enter Position where you want to split the array : “);

int split = enter.nextInt();

for(int i = 0; i < numbers.length; i++){

if(numbers[i] == numbers[split]){

System.out.println(“Split A is “);

for(int j = 0; j < i; j++){

System.out.println(“At Position [“+j+”] = “+numbers[j]);

}// end for loop

System.out.println(“Split B is “);

for(int t = i; t < numbers.length; t++){

System.out.println(“At Position [“+t+”] = “+numbers[t]);

}// end for loop

}// end if

}// end for loop

enter.close();}}

Output:

At Position[0] = 10

At Position[1] = 20

At Position[2] = 30

At Position[3] = 40

At Position[4] = 50

At Position[5] = 60

At Position[6] = 70

At Position[7] = 80

At Position[8] = 90

At Position[9] = 100

Enter Position where you want to split the array : 8

Split A is

At Position [0] = 10

At Position [1] = 20

At Position [2] = 30

At Position [3] = 40

At Position [4] = 50

At Position [5] = 60

At Position [6] = 70

At Position [7] = 80

Split B is

At Position [8] = 90

At Position [9] = 100

 

Leave a Reply

Your email address will not be published. Required fields are marked *

14 + 19 =

This site uses Akismet to reduce spam. Learn how your comment data is processed.