top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Select prime number from the list of given numbers, add them except the smallest prime number?

+1 vote
962 views

Array: 2,5,8,9,6,7,11,13,15,16,18,19,31,33,37,45

OUTPUT

2 is a prime number in the array 
5 is a prime number in the array 
7 is a prime number in the array 
11 is a prime number in the array 
13 is a prime number in the array 
19 is a prime number in the array 
31 is a prime number in the array 
37 is a prime number in the array 
Min 2
Sum 123
posted Aug 27, 2017 by Arindam Nath

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer
  int[] arr = new int[]{2,5,8,9,6,7,11,13,15,16,18,19,31,33,37,45};
  int val=0,sum=0;
  int min = arr[0];

  for(int i=0;i<arr.length;i++){
  boolean isPrime = true;
  if(arr[i]==1){
  isPrime = false;
  }
  else{
  for(int j=2;j<arr[i]/2;j++){
  if(arr[i]%j==0){
  isPrime=false;
  break;
  }
  }
  }

  if(isPrime){
  System.out.println(arr[i] + " is a prime number in the array ");
  for(int l=0;l<arr.length;l++){
  if(min>arr[l]){
  min=arr[l];
  System.out.println("Min "+min);
  }
  }
  val=val+arr[i];
  }
  }
  System.out.println("Min "+min);
  sum = val-min;
  System.out.println("Sum "+sum);
answer Aug 27, 2017 by Panchika Trivedi
pls give this code in c language
Similar Questions
+5 votes

Example :
Let the list be {2,3,5} and Assume always 1 be included then

2th number is 2
3th number is 3
4th number is 4
5th number is 5
6th number is 6
7th number is 8
8th number is 9
9th number is 10
10th number is 12
11th number is 15 and so on...

+2 votes

How to find prime numbers between given intervals? Sample code along with the complexity would be helpful?

+2 votes

Rohit wants to add the last digits of two given numbers.
For example, If the given numbers are 267 and 154, the output should be 11.

Below is the explanation -
Last digit of the 267 is 7
Last digit of the 154 is 4
Sum of 7 and 4 = 11

Write a program to help Rohit achieve this for any given two numbers.

Note: The sign of the input numbers should be ignored. i.e.
if the input numbers are 267 and 154, the sum of last two digits should be 11
if the input numbers are 267 and -154, the sum of last two digits should be 11
if the input numbers are -267 and 154, the sum of last two digits should be 11
if the input numbers are -267 and -154, the sum of last two digits should be 11

+2 votes

Given two strings, append them together (known as "concatenation") and return the result. However, if the concatenation creates a double-char, then omit one of the chars. If the inputs are "Mark" and "Kate" then the output should be "markate". (The output should be in lowercase).

...