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

Karthik Raju 4957

The document contains code for three Java programs. The first program defines a method to read in values for a 2D array, find the largest and second largest elements, and sort the array. The second program defines a method to check if a number is fascinating by multiplying it by 1, 2, and 3, concatenating the results, and checking if the digits are unique. The third program defines a method to check if a number is pronic by testing if it is the product of consecutive integers.

Uploaded by

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

Karthik Raju 4957

The document contains code for three Java programs. The first program defines a method to read in values for a 2D array, find the largest and second largest elements, and sort the array. The second program defines a method to check if a number is fascinating by multiplying it by 1, 2, and 3, concatenating the results, and checking if the digits are unique. The third program defines a method to check if a number is pronic by testing if it is the product of consecutive integers.

Uploaded by

karthik raju
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

KARTHIK RAJU 4957

1
import java.util.*;
public class asort
{
int r,c,i,j,k,tmp,max,n;
Scanner sc= new Scanner(System.in);
public void main (String[] args)
{
System.out.println("give the size of array");
n=sc.nextInt();
if (n<0 && n>20)
{
System.out.println("Invalid row column number");
System.exit(0);
}
else
{
int a[][]=new int[n][n];
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
a[i][j]=sc.nextInt();
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
System.out.print(a[i][j]);
}
System.out.println();
}
System.out.println();System.out.println();
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(a[i][j]>max)
{
max=a[i][j];
r=i+1;
c=j+1;
}
}
}
System.out.println("the largest element "+max+" is in row "+r+" and column "+c);
int p=max;
max=0;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(a[i][j]>max && a[i][j]!=p)
{
max=a[i][j];
r=i+1;
c=j+1;
}
}
}
System.out.println("the second largest element "+max+" is in row "+r+" and column "+c);

// sorting the array


for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
for(k=0;k<n-j-1;k++)
{
if(a[i][k]>a[i][k+1])
{
tmp=a[i][k];
a[i][k]=a[i][k+1];
a[i][k+1]=tmp;
}
}
}
}

for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
System.out.print(a[i][j]);
}
System.out.println();
}

}
}
}

2
import java.util.*;
class fascinating
{
public static void main(String[] args)
{
int i,j,n;
int flag;
String c="123456789";
String a="",str2="";
Scanner sc=new Scanner(System.in);
System.out.println("Please input a number to check whether it is a fascinating number");
n=sc.nextInt();
for(i=1;i<=3;i++)
{
a=a+(n*i);
}
System.out.println(a);
for(char ch='1';ch<='9';ch++)
{
for(j=0;j<a.length();j++)
{
if(ch==a.charAt(j))
str2=str2+a.charAt(j);
}
}

if(str2.equalsIgnoreCase(c))
System.out.println("Fascinating Number");
else
System.out.println("Not a Fascinating Number");
}
}

3
import java.util.*;
class pronic
{
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.");
}
}

You might also like