import [Link].
*;
class Arrays_P1
{
static void main()
{
Scanner sc=new Scanner ([Link]);
[Link]("Enter n");
int n=[Link]();/**stores the size of array*/
int a[]=new int[n];/**stores n integers*/
[Link]("Enter "+n+" integers");
for(int i=0;i<[Link];i++)/**i is used as index number*/
a[i]=[Link]();
int count=0;/**count of numbers divisible 7 or ends with 7*/
int p=1;/**product of even integers*/
[Link]("Negtive numbers list....");
for(int i=0;i<[Link];i++)
{
if(a[i]<0)
[Link](a[i]);
if(a[i]%7==0 || a[i]%10==7)
count++;
if(a[i]%2==0)
p=p*a[i];
}
[Link]("Count of numbers divisible 7 or ends with 7 ="+count);
[Link]("Product of even integers="+p);
}
}
import [Link].*;
class Arrays_P2
{
void main()
{
Scanner sc=new Scanner ([Link]);
int a[]=new int[10];/**stores 10 integers*/
[Link]("Enter 10 integers");
for(int i=0;i<[Link];i++)/**i is used as index number*/
a[i]=[Link]();
[Link]("Perfect Squares...");
for(int i=0;i<[Link];i++)
{
int sqrt=(int)[Link](a[i]);
/**finding square root of a number*/
if(sqrt*sqrt==a[i])
[Link](a[i]);
}
}
}
import [Link].*;
class Arrays_P3
{
static void main()
{
Scanner sc=new Scanner ([Link]);
[Link]("Enter n");
int n=[Link]();/**stores the size of array*/
int marks[]=new int[n];/**stores n integers*/
String names[]=new String[n];
[Link]("Enter "+n+" students marks and names");
for(int i=0;i<[Link];i++)
{ /**i is used as index number*/
names[i]=[Link]();
}
[Link]("students securing 40-60");
for(int i=0;i<[Link];i++)
{
if(marks[i]>=40 && marks[i]<=60)
{
[Link](names[i]+" "+marks[i]);
}
}
[Link]("students securing >=80");
for(int i=0;i<[Link];i++)
{
if(marks[i]>=80)
{
[Link](names[i]+" "+marks[i]);
}
}
}
}
import [Link].*;
class Arrays_P4
{
static void main()
{
Scanner sc=new Scanner([Link]);
char a[]=new char[20];/**stores 20 chars*/
int c1=0;/**count uppercase*/
int c2=0;/**count lowercase*/
int c3=0;/**count digits*/
int c4=0;/**count symbols*/
[Link]("Enter 20 characters");
for(int i=0;i<[Link];i++)/**i - index number*/
{
a[i]=[Link]().charAt(0);
if([Link](a[i]))
c1++;
else if([Link](a[i]))
c2++;
else if([Link](a[i]))
c3++;
else
c4++;
}
[Link]("Count of uppercase="+c1);
[Link]("Count of lowercase="+c2);
[Link]("Count of digits="+c3);
[Link]("Count of symbols="+c4);
}
}
import [Link].*;
class Arrays_P5
{
static void main()
{
Scanner sc=new Scanner([Link]);
int a[]=new int[10];/**stores the average speed*/
int c1=0;/** to count the range 5 to 20*/
int c2=0;/** to count the range 21 to 50*/
int c3=0;/** to count the range 51 to 75*/
int c4=0;/** to count the range 76 to 89*/
int c5=0;/** to count the range 90 to 100*/
[Link]("Enter the average speed of 10 cyclists");
for(int i=0;i<[Link];i++)/**i-index number*/
{
a[i]=[Link]();
if(a[i]>=5 && a[i]<=20)
c1++;
else if(a[i]>=21 && a[i]<=50)
c2++;
else if(a[i]>=51 && a[i]<=75)
c3++;
else if(a[i]>=76 && a[i]<=89)
c4++;
else if(a[i]>=90 && a[i]<=100)
c5++;
}
[Link]("Count of 5 to 20 speed="+c1);
[Link]("Count of 21 to 50 speed="+c2);
[Link]("Count of 51 to 75 speed="+c3);
[Link]("Count of 76 to 89 speed="+c4);
[Link]("Count of 90 to 100 speed="+c5);
}
}
import [Link].*;
class Arrays_P6
{
void main()
{
Scanner sc=new Scanner([Link]);
int a[]=new int[10];/**stores 10 integers*/
[Link]("Enter 10 integers");
int search;/**search element*/
for(int i=0;i<[Link];i++)/**i-index number*/
{
a[i]=[Link]();
}
[Link]("Enter an element to search");
search=[Link]();
boolean found=false;/**flag variable*/
for(int i=0;i<[Link];i++)
{
if(a[i]==search)
{
found=true;
[Link]("found at "+i+" position");
break;
}
}
if(found==false)
[Link]("data not found");
}
}
import [Link].*;
class Arrays_P7
{
void main()
{
Scanner sc=new Scanner([Link]);
double marks[]=new double[10];/**stores 10 marks*/
String names[]=new String[10];/**stores 10 names*/
String search;/**name to search*/
[Link]("Enter 10 names and % marks");
for(int i=0;i<[Link];i++)/**i-index number*/
{
names[i]=[Link]();
marks[i]=[Link]();
}
[Link]("Enter a name to be searched");
search=[Link]();
boolean found=false;/**flag variable*/
for(int i=0;i<[Link];i++)
{
if([Link](names[i]))
{
found=true;
[Link]("Name :"+names[i]);
[Link]("Marks :"+marks[i]);
break;
}
}
if(found==false)
[Link]("Data not found");
}
}
import [Link].*;
public class Arrays_P8
{
static void main() {
Scanner sc=new Scanner([Link]);
char a[]={'Y','W','U','S','P','N','L','K','G','C','A'};
[Link]("Enter the character to search");
char search= [Link]().charAt(0); /**stores a character*/
int lb=0; /**lower boundary*/
int ub=[Link]-1; /**upper boundary*/
int m; /**middle index*/
boolean found=false; /**flag variable*/
while(lb<=ub)
{
m=(lb+ub)/2;
if(search<a[m])
lb=m+1;
else if(search>a[m])
ub=m-1;
else if(search==a[m])
{
found=true;
[Link]("Character found at index number "+m);
break;
}
}
if(found==false)
[Link]("Data not found");
}
}
import [Link].*;
class Arrays_P9
{
void main()
{
Scanner sc=new Scanner([Link]);
double temp[]=new double[10];/** stores the temperatures*/
[Link]("Enter 10 temperatures");
for(int i=0;i<[Link];i++) /**i-index number*/
{
temp[i]=[Link]();
}
for(int i=0;i<[Link]-1;i++)
{
for(int j=0;j<[Link]-i-1;j++)
{
if(temp[j]<temp[j+1])
{
double t=temp[j]; /**t-temporary variable*/
temp[j]=temp[j+1];
temp[j+1]=t;
}
}
}
[Link]("Temperatures in descending order");
for(int i=0;i<[Link];i++)
[Link](temp[i]);
}
}
import [Link].*;
class Arrays_P10
{
void main()
{
Scanner sc=new Scanner([Link]);
String n[]=new String[10];/** stores Organization names*/
[Link]("Enter 10 Organization names");
for(int i=0;i<[Link];i++) /**i-index number*/
{
n[i]=[Link]();
}
for(int i=0;i<[Link]-1;i++)
{
for(int j=0;j<[Link]-i-1;j++)
{
if(n[j].compareToIgnoreCase(n[j+1])>0)
{
String t=n[j]; /**t-temporary variable*/
n[j]=n[j+1];
n[j+1]=t;
}
}
}
[Link]("Organization names in ascending order");
for(int i=0;i<[Link];i++)
[Link](n[i]);
}
}
import [Link].*;
class Arrays_P11
{
void main()
{
Scanner sc=new Scanner([Link]);
int uid[]=new int[10];/**stores 10 uid numbers*/
[Link]("Enter 10 UID numbers");
for(int i=0;i<[Link];i++)/**i-index number*/
uid[i]=[Link]();
int min;/**least number*/
int pos;/**position of least number*/
int t;/**temporary variable*/
for(int i=0;i<[Link]-1;i++)
{
min=uid[i];
pos=i;
for(int j=i+1;j<[Link];j++)
{
if(uid[j]<min)
{
min=uid[j];
pos=j;
}
}
t=uid[i];
uid[i]=min;
uid[pos]=t;
}
[Link]("UID numbers in order");
for(int i=0;i<[Link];i++)
[Link](uid[i]);
}
}
import [Link].*;
class Arrays_P12
{
void main()
{
Scanner sc=new Scanner([Link]);
String n[]=new String[10];/** stores names*/
int m[]=new int[10];/**stores marks*/
[Link]("Enter 10 names and marks");
for(int i=0;i<[Link];i++) /**i-index number*/
{
n[i]=[Link]();
m[i]=[Link]();
}
for(int i=0;i<[Link]-1;i++)
{
for(int j=0;j<[Link]-i-1;j++)
{
if(m[j]>m[j+1])
{
int t=m[j]; /**t-temporary variable*/
m[j]=m[j+1];
m[j+1]=t;
String t1=n[j]; /**t1-temporary variable*/
n[j]=n[j+1];
n[j+1]=t1;
}
}
}
[Link]("Names Marks");
for(int i=0;i<[Link];i++)
[Link](n[i]+" "+m[i]);
}
}
import [Link].*;
class Arrays_P13
{
void main()
{
Scanner sc=new Scanner([Link]);
int a[][]=new int[3][3];/**stores 9 values*/
[Link]("Enter 9 values");
for(int i=0;i<[Link];i++)/**i-row index*/
{
for(int j=0;j<[Link];j++)/**j-column index*/
{
a[i][j]=[Link]();
}
}
int min=a[0][0];/**stores minimum value*/
[Link]("Array in matrix format");
for(int i=0;i<[Link];i++)/**i-row index*/
{
for(int j=0;j<[Link];j++)/**j-column index*/
{
[Link](a[i][j]+" ");
if(a[i][j]<min)
min=a[i][j];
}
[Link]();
}
[Link]("Minimum value is "+min);
}
}
import [Link].*;
class Arrays_P14
{
void main()
{
Scanner sc=new Scanner([Link]);
int a[][]=new int[4][4];/**stores 9 values*/
[Link]("Enter 16 values");
for(int i=0;i<[Link];i++)/**i-row index*/
{
for(int j=0;j<[Link];j++)/**j-column index*/
{
a[i][j]=[Link]();
}
}
int sum1=0;/**sum of primary diagonal values*/
int sum2=0;/**sum of secondary diagonal values*/
for(int i=0;i<[Link];i++)/**i-row index*/
{
for(int j=0;j<[Link];j++)/**j-column index*/
{
[Link](a[i][j]+"\t");
if(i==j)
sum1=sum1+a[i][j];
else if(i+j==3)
sum2=sum2+a[i][j];
}
[Link]();
}
[Link]("sum of primary diagonal values="+sum1);
[Link]("sum of secondary diagonal values="+sum2);
}
}
import [Link].*;
class Arrays_P15
{
void main()
{
Scanner sc=new Scanner([Link]);
int a[][]=new int[3][3];/**stores 9 values*/
[Link]("Enter 9 values");
for(int i=0;i<[Link];i++)/**i-row index*/
{
for(int j=0;j<[Link];j++)/**j-column index*/
{
a[i][j]=[Link]();
}
}
int sum=0;/**sum of each row*/
for(int i=0;i<[Link];i++)/**i-row index*/
{
for(int j=0;j<[Link];j++)/**j-column index*/
{
sum=sum+a[i][j];
}
[Link]("Sum of row "+(i+1)+"="+sum);
sum=0;
}
}
}
import [Link].*;
class Arrays_P16
{
void main()
{
Scanner sc=new Scanner([Link]);
int a[][]=new int[3][3];/**stores 9 values*/
int count=0;/**count of even numbers*/
int p=1;/**product of odd values*/
[Link]("Enter 9 values");
for(int i=0;i<[Link];i++)/**i-row index*/
{
for(int j=0;j<[Link];j++)/**j-column index*/
{
a[i][j]=[Link]();
if(a[i][j]%2==0)
count++;
else
p=p*a[i][j];
}
}
[Link]("Count of even numbers="+count);
[Link]("Product of oddn numbers="+p);
}
}
import [Link].*;
class Arrays_P17
{
void main()
{
Scanner sc=new Scanner([Link]);
int a[][]=new int[3][3];/**stores 9 values*/
int count=0;/**count of 0's*/
[Link]("Enter 9 values");
for(int i=0;i<[Link];i++)/**i-row index*/
{
for(int j=0;j<[Link];j++)/**j-column index*/
{
a[i][j]=[Link]();
if(a[i][j]==0)
count++;
}
}
if(count>(9-count))
[Link]("Sparse Matrix");
else
[Link]("Not a Sparse Matrix");
}
}