Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
995dc51
commit 07e3991
Showing
4 changed files
with
243 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package javaapplication3; | ||
|
||
/** | ||
* @date 14/01/19 | ||
* @author SPREEHA DUTTA | ||
*/ | ||
import java.util.*; | ||
public class Freq { | ||
public static void main(String []args) | ||
{ | ||
int n;int i;int t;int k=0; | ||
Scanner sc=new Scanner(System.in); | ||
System.out.println("Enter number of elements in the array "); | ||
n=sc.nextInt(); | ||
int arr[]=new int[n]; | ||
System.out.println("Enter elements of the array "); | ||
for(i=0;i<n;i++) | ||
arr[i]=sc.nextInt(); | ||
Arrays.sort(arr); | ||
if(n!=1){ | ||
if(arr[0]==arr[1]) | ||
k=1; | ||
} | ||
else | ||
System.out.println("frequency of "+arr[0]+" is "+1); | ||
for(i=1;i<n;i++) | ||
{ | ||
if(arr[i]==arr[i-1]) | ||
k++; | ||
else | ||
{ | ||
System.out.println("frequency of "+arr[i-1]+" is "+k); | ||
k=1; | ||
} | ||
} | ||
if(n!=1) | ||
System.out.println("frequency of "+arr[i-1]+" is "+k); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package javaapplication3; | ||
|
||
/** | ||
* @date 14/01/19 | ||
* @author SPREEHA DUTTA | ||
*/ | ||
import java.util.*; | ||
public class Power { | ||
public static void main(String []args) | ||
{ | ||
Scanner sc=new Scanner(System.in); | ||
int n,p;int i,j;int k=0; | ||
System.out.println("Enter size of the array "); | ||
n=sc.nextInt(); | ||
ArrayList<Integer> arr1 = new ArrayList<Integer>(n); | ||
ArrayList<Integer> arr2 = new ArrayList<Integer>(n); | ||
System.out.println("Enter elements of the first array "); | ||
for(i=0;i<n;i++) | ||
arr1.add(sc.nextInt()); | ||
System.out.println("Enter elements of the second array "); | ||
for(i=0;i<n;i++) | ||
arr2.add(sc.nextInt()); | ||
System.out.println("Enter power"); | ||
p=sc.nextInt(); | ||
for(i=0;i<n;i++) | ||
{ | ||
int t=(int)(Math.pow(arr1.get(i),p)); | ||
if(arr2.contains(t)) | ||
k++; | ||
} | ||
if(k==n) | ||
System.out.println("true"); | ||
else | ||
System.out.println("false"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package javaapplication3; | ||
|
||
/** | ||
* @date 14/01/19 | ||
* @author SPREEHA DUTTA | ||
*/ | ||
import java.util.*; | ||
public class Unique { | ||
public static void countUniques(int arr[]) | ||
{ | ||
int k=1; | ||
for(int i=1;i<arr.length;i++) | ||
{ | ||
if(arr[i]!=arr[i-1]) | ||
k++; | ||
} | ||
System.out.println("Number of unique elements = "+k); | ||
} | ||
public static void main(String []args) | ||
{ | ||
int n;int i; | ||
Scanner sc=new Scanner(System.in); | ||
System.out.println("Enter number of elements"); | ||
n=sc.nextInt(); | ||
int arr[]=new int[n]; | ||
System.out.println("Enter elements of the array "); | ||
for(i=0;i<n;i++) | ||
arr[i]=sc.nextInt(); | ||
countUniques(arr); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters