0% found this document useful (0 votes)
0 views

ALLJAVA

Uploaded by

Ojasverma
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)
0 views

ALLJAVA

Uploaded by

Ojasverma
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
You are on page 1/ 4

GOLD BATCH NUMBER

import java.util.*;
class gold
{
int n;
gold()
{
n=0;
}
void input ()
{
Scanner sc=new Scanner(System.in);
System.out.println("enter the values of n: ");
n=sc.nextInt();
if(n<=9||n>=50)
{
System.out.println("invalid input out of range");
return;
}
if(n%2!=0)
{
System.out.println("invalid no. no is odd");
return;
}
}
boolean isprime(int num)
{
int c=0;
for(int i=1;i<=num;i++)
{
if(num%i==0)
{
c++;
}
}
return c==2;
}
void calculate()
{
System.out.println("prime pairs");
{
int a=3;
int b=0;
while(a<=n/2)
{
b=n-a;
if(isprime(a) && isprime(b))
{
System.out.println(a+","+b);
}
a+=2;
}
}
}
public static void main(String args[])
{
gold obj=new gold();
obj.input();
obj.calculate();
}
}
BANNER PROGRAM
import java.util.*;
class banner
{
int n;
String names[];
banner()
{
n=0;
names=null;
}
void read()
{
Scanner sc=new Scanner(System.in);
System.out.println("enter the value of n:");
n=sc.nextInt();
if(n<=2||n>=9)
{
System.out.println("invalid output");
return;
}
names=new String[n];

for(int i=0;i<n;i++)
{
System.out.println("teams"+(i+1)+":");
names[i]=sc.nextLine();
}
}
void print()
{
int max=0;
for(int i=0;i<n;i++)
{
if(names[i].length()>max)
max=names[i].length();
}
for(int i=0;i<max;i++)
{
for(int j=-0;j<names.length;j++)
{
if(i<names[j].length())
System.out.print(names[j].charAt(i)+"\t");
}
System.out.println();
}
}
public static void main(String args[])
{
banner obj=new banner();
obj.read();
obj.print();
}
}

You might also like