Java | JSP | JSF Answers

Questions: 4 418

Answers by our Experts: 3 943

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search & Filtering

Task #3: Arrays and Methods

In this task, you are being asked to write a method that manipulates arrays in Java.

Write a method called printCommon that accepts two integer arrays as arguments and

print all the common elements from the two arrays.

You may use the following header for this method:

static void printCommon(int[] firstArray, int[]

secondArray)

For example, if the elements of two arrays are {4, 2, 3, 17, 19, 12, 16, 7, 100}

and {3, 9, 5, 12, 6, 17, 8, 7}, then the method should print {3, 17, 12, 7}.

NOTE:

● Declare and initialize both arrays without taking input from user.

● Both arrays do not need to be of the same size.

1. Create a program called ArrayPrintCommonLab2.java

2. Correctly display appropriate messages.


Task #2: Arrays and Methods

In this task, you are being asked to write a method that manipulates an array in Java.

Write a method called printPrimes that accepts one integer array as argument and print

all the prime numbers form the array.

You may use the following header for this method:

static void printPrimes(int[] array)

For example, if you pass {2, 4, 31, 12, 7, 47, 63, 41, 67, 55} to this

method, then the method should print 2, 31, 7, 47, 41, 67, as prime numbers.

To help with finding a prime number, the printPrimes() method would call another method:

static boolean isPrime(int number)

that takes an integer as an argument, and returns true if that number is a prime, otherwise,

returns false.

NOTE: Declare and initialize the array without taking input from user.

1. Create a program called ArrayPrintPrimesLab2.java

2. Correctly display appropriate messages.


Task #1: Arrays and Methods

In this task, you are being asked to write a method that manipulates an array in Java.

Write a method called sumEvenOdd that accepts one integer array as argument and prints

the sum of all even and odd numbers in separate lines.

You may use the following header for this method:

static void sumEvenOdd(int[] array)

For example, if we pass {3, 2, 12, 15, 17, 22, 25, 26, 28} to this method,

then the method should print:

Sum of all even numbers: 90

Sum of all odd numbers: 60

NOTE: Declare and initialize the array without taking input from user.

1. Create a program called ArraySumEvenOddLab2.java

2. Correctly display appropriate messages.


Write a program that accepts a number from 1 to 365 and determine equivalent date. You may use any

Control Statement.


Store employee data that obtains from user and the input process stops when the user says no longer wants to enter any data


Write a program that accepts a number from 1 to 365 and determine equivalent date. You may use any Control Statement.


Example Output of the Program:


Input a number from 1 to 365: 1

Your number’s equivalent in date is: January 1


Write a program to create a single dimension array to store marks of 25 students. Then display the frequency of students in the range of marks:

0-30

31-50

51-75

76-90

91-100

Hint: 1)Use java.util package

2) Use linear searching


Write a program to create an array in order to store 30 numbers then display the highest number and second highest number present in it using bubble sorting.

The program must be written like-

/*To display the highest number and second highest number*/

import java.util.*;

class Highest

{

public static void main(String args[])

{

Scanner sc = new Scanner(System.in);

int a[]=new int[30];

int i; //To control loop

int j,d; //For using in swapping elements in bubble sorting

int n; //For controlling highest number

System.out.println("Enter 30 numbers");

for(i=0;i<30;i++)

{

a[i] = sc.nextInt();

}

// Stored 30 numbers in an array

for(i=0;i<29;i++)

{

for(j=0;j<29-i;j++)

{

if(a[j] < a[j+1])

{

d = a[j];

a[j] = a[j+1];

a[j+1] = d;

// Elements swapped in descending order

}

}

}

Find the highest and second highest number in the array i.e. a[30]


Write a program to create two SDA to store names and marks of 25 students.Then display the name of the students who secured more than 90 as per their marks in descending order. And also display how many such students found.

write a function solution that, given a three-digit integer n and an integer K, returns a maximum possible three-digit value that can be obtained by performing at most K increases by 1 of any digit in N in java 8