Documente Academic
Documente Profesional
Documente Cultură
MOBIUS FUNCTION
import java.util.*;
public class mobiusfn
{
int n;
mobiusfn()
{
n=0;
}
void input()
{
Scanner sc=new Scanner(System.in);
System.out.println("enter a number");
n=sc.nextInt();
}
int primefac()
{
int a=n, i=2, m=0, c=0, f=0;
while(a>1)
{
c=0;
while(a%i==0)
{
c++;
f++;
a=a/i;
i++;
}
if(c>1)
return 0;
}
return f;
}
void display()
{
int mob,x;
if(n == 1)
mob = 1;
else
{
x = primefac();
if(x == 0)
mob = 0;
else
mob = (int)Math.pow(-1,x);
}
System.out.println("Value of Mobius Function : "+mob);
}
if(str2.equalsIgnoreCase(c))
System.out.println("Fascinating Number");
else
System.out.println("Not a Fascinating Number");
}
}
// 3. PRONIC NUMBER
import java.util.*;
class pronic_number
{
public static void main(String [] args)
{
int n,i,k=1;
int flag=0;
Scanner sc =new Scanner(System.in);
System.out.println("input a number to check whether it is a pronic number or
not.");
n=sc.nextInt();
for(i=0;i<n;i++)
{
if((i*k)==n)
flag=1;
k++;
}
if(flag==1)
System.out.println(n+" is a Pronic Number.");
else
System.out.println(n+" is not a Pronic Number.");
}
}
// 4. DECIMAL TO HEXADECIMAL
import java.util.*;
class decitohexa
{
public static void main(String[] args)
{
int i,d,n;
String s="";
Scanner sc =new Scanner(System.in);
System.out.println("please give a number");
n=sc.nextInt();
for(i=n;i>0;i=i/16)
{
d=i%16;
if(d>9)
{
switch(d)
{
case 10:
s='A'+s;
break;
case 11:
s='B'+s;
break;
case 12:
s='C'+s;
break;
case 13:
s='D'+s;
break;
case 14:
s='E'+s;
break;
case 15:
s='F'+s;
break;
}
}
else
{
s=d+s;
}
}
System.out.println("the hexadecimal value of "+n+" is "+s);
}
}
// 5. FINDDAYS
import java.util.*;
public class finddays
{
public void main(String[] args)
{
int month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
finddays ob=new finddays();
Scanner sc=new Scanner(System.in);
System.out.println("give date1");
System.out.println("give date");
int dt1=sc.nextInt();
System.out.println("give month");
int mn1=sc.nextInt();
System.out.println("give year");
int yr1=sc.nextInt();
System.out.println("give date2");
System.out.println("give date");
int dt2=sc.nextInt();
System.out.println("give month");
int mn2=sc.nextInt();
System.out.println("give year");
int yr2=sc.nextInt();
if(validdate(dt1,mn1,yr1) && validdate(dt2,mn2,yr2))
{
month[2]=ob.isleapyr(yr1);
int a=ob.dayno(dt1,mn1,yr1);
month[2]=ob.isleapyr(yr2);
int b=ob.dayno2(dt2,mn2,yr2);
if(yr2!=yr1)
{
double tot=Math.abs((yr1+1)-(yr2-1))*365.25;
double totdays=tot+a+b;
System.out.println(totdays);
}
else
{
int totdays=a+b;
System.out.println(totdays);
}
}
}
return false;
else
return true;
}
int month[];
int dayno(int d,int m,int y)
{
int d1=0;
for(int i=m;i<13;i++)
{
d1=month[i]+d1;
}
return d1;
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
System.out.print(a[i][j]);
}
System.out.println();
}
}
}
}
// 7. ARRAY
import java.util.*;
public class arrayy
{
public static void main(String[]args)
{
int tmp,i,j,n,m;
Scanner sc=new Scanner(System.in);
System.out.println("input the number of rows in the array");
m=sc.nextInt();
System.out.println("input the number of columns in the array");
n=sc.nextInt();
if(m>20&&n>20 || m<2&&n<2)
{
System.out.println("Invalid row column number");
System.exit(0);
}
else
{
int a[][]=new int[m][n];
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
a[i][j]=sc.nextInt();
}
}
// display original array
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
System.out.print(a[i][j]);
}
System.out.println();
}
// sorting the border elements
for(j=0;j<n;j++)
{
for(i=0;i<m;i++)
{
if(a[j][i]>a[j][m-1])
{
tmp=a[j][i];
a[j][i]=a[j][m-1];
a[j][m-1]=tmp;
}
}
}
System.out.println(); System.out.println();