0% found this document useful (0 votes)
9 views6 pages

Programs

Uploaded by

arceus7800
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views6 pages

Programs

Uploaded by

arceus7800
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

// Unique Number

/*
* UID:
* INDEX NO.
*/
import java.util.*;
class Unique
{
//To check whether number is unique or not
static boolean isUnique(int num)
{
boolean f=true;
int c=0,a[]=new int[10];
//To extract the digits
while(num!=0)
{
int d=num%10;
a[d]=a[d]+1;
num/=10;
}
for(int i=0;i<10;i++)
{
if(a[i]>1)
{
f=false; // No. is not unique
}
}
return f; // No. is Unique
}
//To execute
public static void main()
{
int m,n,count=0;
Scanner sc=new Scanner(System.in);
System.out.print("m=");
m=sc.nextInt();
System.out.print("n=");
n=sc.nextInt();
if(m>=n||m>=30000||n>=30000)
{
System.out.println("Invalid Range");
}
else
{
System.out.print("THE UNIQUE-DIGITS INTEGERS ARE: ");
for(int i=m;i<=n;i++)
{
if(isUnique(i)==true)
{
count++;
System.out.print(i+",");
}
}
if(count==0)
System.out.println("NIL");
System.out.println("\nFREQUENCY OF UNIQUE-DIGITS INTEGERS IS :"+count);
}
}
}

// Goldbach number
import java.util.*;
class Goldbach
{
//To check number is prime or not
boolean isprime(int n)
{
int c=0;
for(int i=2;i<n;i++)
{
if(n%i==0)
{
return false;
}
}
return true;
}
public static void main()
{
Scanner sc=new Scanner(System.in);
Goldbach ob=new Goldbach();
System.out.print("N = ");
int num=sc.nextInt();
if(num%2!=0)
{
System.out.println("INVALID INPUT");
}
else
{
System.out.print("ODD PRIME PAIRS ARE: ");
for(int i=3;i<=num/2;i++)
{
if(ob.isprime(i) && ob.isprime(num-i))
{
System.out.println(i+","+(num-i));
}
}
}
}
}//End of class

//Matrix shift rows


import java.util.*;
class ShiftMatrix
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int m,n,max,i,j,c=0,r=0,A[][],B[];
System.out.print("M= ");
m=sc.nextInt();
System.out.print("N= ");
n=sc.nextInt();
if((m>=10 || m<=2)||(n>=10 || n<=2))
{
System.out.println("SIZE OUT OF RANGE.INVALID ENTRY");
}
else
{
A=new int[m][n];
B=new int[n];
//To input
System.out.println("Enter elements in the Matrix");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
A[i][j]=sc.nextInt();
}
}
System.out.println("Original Matrix");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
System.out.print(A[i][j]+"\t ");
}
System.out.println();
}
max=A[0][0];
//To shift rows of Matrix upward

for(j=0;j<n;j++)
{
B[j]=A[0][j];
}

for(i=1;i<m;i++)
{
for(j=0;j<n;j++)
{
A[i-1][j]=A[i][j];
}
}
for(j=0;j<n;j++)
{
A[m-1][j]=B[j];
}

System.out.println("FORMED MATRIX AFTER ROTATING");


for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
//To find highest element
if(max<A[i][j])
{
max=A[i][j];
r=i;
c=j;
}
System.out.print(A[i][j]+"\t"); //To display elements of the matrix
}
System.out.println();
}
System.out.println("\nHighest element: "+max +" (Row : "+r+" and Column :"+c+")");
}
}
}

// String vowel/consonants
import java.util.*;
class StringVoCo
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.print("INPUT :");
String sent=sc.nextLine();
char lch=sent.charAt(sent.length()-1);
if(lch!='.' && lch!='?')
{
System.out.println("Invalid input");
}
else
{
StringTokenizer st=new StringTokenizer(sent, " .?");
int count=st.countTokens(); // To count no. of words
String newsent="";
String wrd[]=new String[count]; // To store all individual words
int vo[]=new int[count]; // To store no. of vowels
int co[]=new int[count]; // To store no. of consonants
for(int i=0;i<count;i++)
{
wrd[i]=st.nextToken(); // To extract the word
wrd[i]=Character.toUpperCase(wrd[i].charAt(0))+wrd[i].substring(1);
String vow="AEIOUaeiou";
int c=0;
int v=0;
for(int j=0;j<wrd[i].length();j++)
{
char ch=wrd[i].charAt(j);
if(vow.indexOf(ch)!=-1)
v++;
else
c++;
}
vo[i]=v;
co[i]=c;
newsent+=wrd[i]+" ";
}
System.out.println(newsent);
System.out.println("Word\t\tVowels\t\tConsonants");
for(int i=0;i<count;i++)
System.out.println(wrd[i]+"\t\t"+vo[i]+"\t\t"+co[i]);
}
}
}

You might also like