Pratin
Pratin
Pratin
import java.util.Scanner;
class Pratin1
{
public static void main(String[] args)
{
//2 3 5 11 23 29 41 53 83 89
for(int i=1;i<=num;i++)
{
if(num%i==0)
{
++c;
}
}
if(c==2)
{
return true;
}
else
{
return false;
}
}
2)/////////////////////////////////////////////////////////////////
import java.util.Scanner;
class Pratin2
{
public static void main(String[] args)
{
//1 -2 6 -15 31 -56 92 -141 205 -286
int n=s.nextInt();
int k=1;
for(int i=0;i<n;i++)
{
k=k+(i*i);
if(i%2==0)
{
System.out.print(k+" ");
}
else
{
System.out.print("-"+k+" ");
}
}
}
}
3)/////////////////////////////////////////////////////////////////////////////
import java.util.Scanner;
class Pratin3
{
public static void main(String[] args)
{
//1 1 2 12 14 26 40 264 304 568
Scanner s=new Scanner(System.in);
System.out.println("enter the n");
int n=s.nextInt();
int a=1;
int b=1;
int c=1;
for(int i=0;i<n;i++)
{
if(i<2)
{
System.out.print(a+" ");
}
else
{
c=a+b;
if((i+1)%4==0)
{
c=c*4;
}
System.out.print(" "+c+" ");
a=b;
b=c;
}
}
}
}
4)/////////////////////////////////////////////////////////////
import java.util.Scanner;
class Pratin5
{
public static void main(String[] args)
{
//4 6 12 18 30 42 60 72
System.out.println("Enter limit:");
Scanner inp=new Scanner(System.in);
int n=inp.nextInt();
int count;
for(int i=3;i!=n;i++)
{
count=0;
for(int j=2;j<=(i-1)/2;j++)
{
if((i-1)%j==0)
{
count++;
break;
}
}
for(int j=2;j<=(i+1)/2;j++)
{
if((i+1)%j==0)
{
count++;
break;
}
}
if(count==0)
{
System.out.println(i);
}
}
}
}
5)////////////////////////////////////////////////////////////////
import java.util.Scanner;
class Pratin6
{
public static void main(String[] args)
{
//11 41 102 196 325
Scanner s=new Scanner(System.in);
System.out.println("enter the num");
int n=s.nextInt();
int ar[]=new int[n];
int k=11;
int j=1;
for(int i=0;i<n;i++)
{
System.out.println(k);
k=(k+30*j)+i*i;
j=j+1;
}
}
}
6)////////////////////////////////////////////////////////////////
import java.util.Scanner;
class Pratin4
{
public static void main(String[] args)
{
//2 3 5 7
Scanner s=new Scanner(System.in);
System.out.println("enter the n");
int n=s.nextInt();
for(int i=2;i<=n;i++)
{
if(is_prime(i)==true)
{
System.out.println(i);
}
}
}
static boolean is_prime(int num)
{
for(int i=2;i<=num/2;i++)
{
if(num%i==0)
{
return false;
}
}
return true;
}
}
7)////////////////////////////////////////////////////////////////////////
import java.util.Scanner;
class Pratin7
{
public static void main(String[] args)
{
//1 3 7 13 21 43 57 73 91 111
int i=2;
int j=1;
Scanner s=new Scanner(System.in);
System.out.println("enter the range");
int n=s.nextInt();
for(int l=1;l<=n;l++)
{
System.out.println(j);
if(l>=5&&l%5==0)
{
j=j+i;
i=i+2;
}
j=j+i;
i=i+2;
}
}
}
8)///////////////////////////////////////////////////////////
class Pratin8
{
public static void main(String[] args)
{
int a = 7;
int count = 0;
int cal = 0;
while(true) {
cal = cal + a;
if(cal%2==1 && cal%3==1 && cal%4==1 && cal%5==1 && cal%6==1) {
count++;
if(count==1 || count==2 || count==4||count==5)
System.out.print(cal + " ");
}
}
}
}
9)/////////////////////////////////////////////////////////////////////
import java.lang.Math;
import java.util.Scanner;
class Pratin9
{
public static void main(String[] args)
{
//Write the program to generate the following series
//where N which is upper limit should be taken as an input.
//Also, display the count of the numbers which have the digit '9' in
them.
//For example, if the value of N is 2800 the output should be as
follows
}
number=number/10;
}
}
else
{
count=0;
continue;
}
}
}
System.out.println(occur);
}
public static boolean is_prime(int num)
{
for(int i=2;i<=num/2;i++)
{
if(num%i==0)
{
return false;
}
}
return true;
}
10)//////////////////////////////////////////////////////////////////////////
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
class Pratin10
{
public static void main(String[] args)
{
//Write a program to rearrange a 4 digit number in ascending
//order of digits. Eg: 3921 to 1239
Scanner s=new Scanner(System.in);
System.out.println("enter the num");
long num=s.nextLong();
System.out.println(smallest(num));
return result;
}
}
11)//////////////////////////////////////////////////////////////////
import java.util.Scanner;
class Pratin11
{
public static void main(String[] args)
{ /// 6,15,35,77,143,221,323,437
//2*3 3*5 5*7 7*11 ......
Scanner s=new Scanner(System.in);
System.out.println("enter the num");
int n=s.nextInt();
int c=0;
int j=0;
int ar[]=new int[n];
for(int i=2;c<n;i++)
{
if(is_prime(i)==true)
{
ar[j++]=i;
++c;
}
}
for(int i=0;i<ar.length;i++)
{
System.out.println(ar[i]);
}
for(int i=0;i<ar.length-1;i++)
{
System.out.println(ar[i]*ar[i+1]);
}
}
public static boolean is_prime(int n)
{
for(int i=2;i<=n/2;i++)
{
if(n%i==0)
{
return false;
}
}
return true;
}
12)////////////////////////////////////////////////
import java.util.Scanner;
import java.lang.Math;
class Pratin12
{
public static void main(String[] args)
{
//1^3+2=3.
//2^3+3=11.
//3^3 +4=31.
//4^3+5=69.
//5^3+6=13
Scanner s=new Scanner(System.in);
System.out.println("enter the number");
int n=s.nextInt();
int j=2;
for(int i=1;i<=n;i++)
{
System.out.println(((int)Math.pow(i,3))+j);
j++;
}
}
}
13)//////////////////////////////////////////////////////
import java.util.Scanner;
import java.lang.Math;
class Pratin13
{
public static void main(String[] args)
{
//23–2=21
//21+3^2=30
//30–5=25
//25+7^2=74
//74–11=63
//63+13^2=232..
Scanner s=new Scanner(System.in);
System.out.println("enter the number");
int n=s.nextInt();
int sum=23;
int c=0;
int j=1;
System.out.println(sum);
for(int i=2;c<n-1;i++)
{
if(is_prime(i)==true&&j%2==1)
{
sum=sum-i;
System.out.println(sum);
j=j+1;
++c;
}
else if(is_prime(i)==true&&j%2==0)
{
sum=sum+(int)Math.pow(i,2);
System.out.println(sum);
j=j+1;
++c;
}
}
}
static boolean is_prime(int n)
{
for(int i=2;i<=n/2;i++)
{
if(n%i==0)
{
return false;
}
}
return true;
}
}
14)//////////////////////////////////////////////////////////
import java.util.Scanner;
class Pratin
{
public static void main(String[] args)
{
////4 6 12 18 30 42
}
static boolean is_prime(int n)
{
for(int i=2;i<=n/2;i++)
{
if(n%i==0)
{
return false;
}
}
return true;
}
}
15)///////////////////////////////////////////
6×3−4=14
14×3−6=36
36×3−10=98
98×3−18=276
16)////////////////////////////////////////////////////
//8 6 9 23 27 429
//(8*1)-2=6,
//(6*2)-3=9,
//(9*3)-4=23,
//(23*4)-5=87,
//(87*5)-6=429,