Tuesday, November 19, 2019

ISC COMPUTER SCIENCE QUESTION PRACTICAL PAPER 2019 | QUESTION NUMBER 2 | Follow on youtube for more |




import java.util.*;
public class qstn_2
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of elements");
int n = sc.nextInt();

if(n<=2||n>=10)
{
System.out.println("MATRIX SIZE OUT OF RANGE");
System.exit(0);
}

int a[] =new int[n];
//Taking array input
System.out.println("ENTER ELEMENTS OF SINGLE DIMENSIONAL ARRAY:");
for(int i=0;i<n;i++)
{
a[i] = sc.nextInt();
}

//sorting the array elements

int temp = 0;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(a[i]<a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}

// Displaying the sorted array
System.out.print("\nSORTED ARRAY: ");
for(int i=0;i<n;i++)
{
System.out.print(a[i]+" ");
}

System.out.println();
int row = n;
int column = n;
int position = 0;

System.out.println("\nFILLED MATRIX");
for(int i=0;i<row;i++)
{
for(int j=0;j<column;j++)
{
System.out.print(a[j]+" ");
}
for(int j=0;j<position;j++)
{
System.out.print(a[j]+" ");
}
System.out.println();
position++;
column--;
}
}
}

No comments:

Post a Comment

ICSE COMPUTER SCIENCE SPECIMEN PAPER | QUESTION 7 | PLEASE DO WATCH THE VIDEO

  import  java.util.*; class icse_specimen_1 {     public static void main(String[] args)     {         Scanner sc1 = new Scanner(System.in)...