This is a continuation of array in BlueJ for ICSE Schools. Previously we have seen some programs on array in java. Few programs common in ICSE computer applications sample papers are given below.
Program No 1
In the following program the user will put the month number (1 to 12), date and year. Our program will display the total number days from the start of the year.
class MyDate
{
int month,day,tday,year,i,lip=0,a=1,b=1;
int dpm[12]={31,28,31,30,31,30,31,31,30,31,30,31};
public void setData(int d,int mon, int year)
{
for(i=0; i< mon-1; i++)
{
tday=tday+dpm[i];
}
for(i=0; i< 2; i++)
{
if(year%10!=0)
break;
year=year/10;
}
if(i==2)
{
if(year%400==0)
lip=1;
}
else if(year%4==0)
lip=1;
if((lip==1)&&(mon > 2))
tday=tday+1;
System.out.println("total days from start of the year is::"+tday);
}
}
Program No 2
This type of program is very common in icse sample papers. Generate the series 1,4,7,10.....50th element and generate the values of the element of 18th,49th,27th (print series)
{
int num[] new int[50];
int i,no=1;
public void show()
{
for(i=0;i< 50;i++)
{
num[i]=no;
no=no+3;
}
System.out.println ("The series is: -\n");
for(i=0;i< 50;i++)
{
System.out.println num[i]);
}
System.out.println ("\n*************\n");
System.out.println ("Value of the element at 18th position:" + num[17]);
System.out.println ("Value of the element at 49th position:" + num[48]);
System.out.println ("Value of the element at 27th position:” + num[26]);
}
}
}
Program No 3
In this program on Bluej for icse schools. Input an array of 20 integers, they can be +ve, -ve or zero . i) count the number of +ve, -ve and zero values ii) count the number of even numbers and odd numbers iii) prime numbers in the array
import java.io.*;
class Count
{
int a[] new int[20];
int i,j,odd=0,even=0, pos=0,neg=0,zero=0,prime=0,flag;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void take() throws IOException
{
for(i=0;i< 20;i++)
{
System.out.println("enter a value:-");
a[i]=Integer.parseInt(br.readLine());
}
for(i=0;i< 20;i++)
{
System.out.println(a[i]);
}
for(i=0;i< 20;i++)
{
flag=0;
if(a[i] >0)
pos++;
else if(a[i]< 0)
neg++;
else
zero++;
if(a[i]%2==0)
even++;
else
odd++;
for(j=2;j< a[i];j++)
{
flag=1;
if(a[i]%j==0)
break;
}
if(((j==a[i])||(flag==0))&&(a[i]>0)&&(a[i]!=0))
prime++;
}
System.out.println(" (+)ve="+pos );
System.out.println(" (-)ve=" + neg );
System.out.println(" Odd="+ odd);
System.out.println(" Even=" + even);
System.out.println("Zero=" + zero);
System.out.println("Prime=" + prime);
}
}
This site is on Bluej for icse schools. If you have any doubt in any program, pl. feel free to put your comments. I am here to clear your doubts.
Related Post: BlueJ Programs on Numeric Array
Related Post: BlueJ Programs on Numeric Array
No comments:
Post a Comment