For Details of The Program: CLICK HERE
import java.io.*;
class Mat
{
int a[], N,b[][];
public void takeValues()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int i;
System.out.print("\nENTER N=");
N=Integer.parseInt (br.readLine());
if (N<=1 || N>=12)
{
System.out.print("\nMATRIX SIZE OUT OF RANGE");
return;
}
a=new int[N];
b=new int[N][N];
for(i=0;i<=N-1;i++)
{
System.out.print("\nINPUT:");
a[i]=Integer.parseInt (br.readLine());
}
arrange();
}
private void arrange()
{
int i,j,k,x,temp;
for(i=0;i<=N-2;i++)
{
for(j=i+1;j<=N-1;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
System.out.print("\nSORTED ARRAY\n");
for(i=0;i<=N-1;i++)
System.out.print(a[i]+" ");
for(i=0;i<=N-1;i++)
{
for(j=0;j<=N-1-i;j++)
{
b[i][j]=a[j];
}
x=j;
for(k=0;k<=i-1;k++)
{
b[i][x++]=a[k];
}
}
System.out.print("\nFILLED MATRIX\n");
for(i=0;i<=N-1;i++)
{
for(j=0;j<=N-1;j++)
{
System.out.print(b[i][j]+" ");
}
System.out.println();
}
}
public static void main(String args[]) throws IOException
{
Mat ob=new Mat();
ob.takeValues();
}
}
Back To 2019 Computer Practical Paper: CLICK HERE
import java.io.*;
class Mat
{
int a[], N,b[][];
public void takeValues()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int i;
System.out.print("\nENTER N=");
N=Integer.parseInt (br.readLine());
if (N<=1 || N>=12)
{
System.out.print("\nMATRIX SIZE OUT OF RANGE");
return;
}
a=new int[N];
b=new int[N][N];
for(i=0;i<=N-1;i++)
{
System.out.print("\nINPUT:");
a[i]=Integer.parseInt (br.readLine());
}
arrange();
}
private void arrange()
{
int i,j,k,x,temp;
for(i=0;i<=N-2;i++)
{
for(j=i+1;j<=N-1;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
System.out.print("\nSORTED ARRAY\n");
for(i=0;i<=N-1;i++)
System.out.print(a[i]+" ");
for(i=0;i<=N-1;i++)
{
for(j=0;j<=N-1-i;j++)
{
b[i][j]=a[j];
}
x=j;
for(k=0;k<=i-1;k++)
{
b[i][x++]=a[k];
}
}
System.out.print("\nFILLED MATRIX\n");
for(i=0;i<=N-1;i++)
{
for(j=0;j<=N-1;j++)
{
System.out.print(b[i][j]+" ");
}
System.out.println();
}
}
public static void main(String args[]) throws IOException
{
Mat ob=new Mat();
ob.takeValues();
}
}
Back To 2019 Computer Practical Paper: CLICK HERE
No comments:
Post a Comment