Page 1 of 1 |
From: akash5 | Reply 1 of 10 | Reply | |
Subject: Contributed Answer/Explanation to Q. 3 |
java
import java.io.*;<br />
class exam2001<br />
{ public static void main (String args[]) throws IOException<br
/>
{ int s[]=new int [5];<br />
int a[]=new int [5];<br />
int c[]=new int [11];<br />
int i,l,j;//for s<br />
int I,L,J; //for a<br />
DataInputStream in = new DataInputStream (System.in);<br
/>
System.out.println("s[i] :");<br />
for ( i=0;i<=4;i++)<br />
{ System.out.print ("no. "); <br />
s[i] =Integer.parseInt(in.readLine());<br />
}<br />
System.out.println("a[i] :");<br />
for ( I=0;I<=4;I++)<br />
{ System.out.print ("no. "); <br />
a[I] =Integer.parseInt(in.readLine());<br />
}<br />
for ( i=0;i<5;i++)<br />
{for ( j=0;j<5-i-1;j++)<br />
{if (s[j]>s[j+1])<br />
{ l=s[j];<br />
s[j]=s[j+1];<br />
s[j+1]=l;<br />
}} }<br />
for ( I=0;I<5;I++)<br />
{ for ( J=0;J<5-I-1;J++)<br />
{ if (a[J]>a[J+1])<br />
{ L=a[J];<br />
a[J]=a[J+1];<br />
a[J+1]=L;<br />
} }}<br />
System.out.println("s[i] :");<br />
for ( i=0;i<=4;i++)<br />
{ System.out.println(s[i]);}<br />
<br />
System.out.println("a[I] :");<br />
for ( I=0;I<=4;I++)<br />
{System.out.println(a[I]); }<br />
<br />
int x,y;<br />
// to merge n sort array s & a in c.....<br />
for(x=0,i=0,I=0;x<10;x++)<br />
{ if(s[i]<a[I])<br />
{ c[x]=s[i];<br />
i++;<br />
if(i>=5)<br />
{ for(x++;I<5;I++,x++)<br />
c[x]=a[I]; }
}<br />
else<br />
{ c[x]=a[I];<br />
I++;<br />
if(I>=5)<br />
{ for(x++;i<5;i++,x++)<br />
c[x]=s[i];<br />
} } }<br />
System.out.println("The c[x] is : ");<br />
for(x=0;x<20;x++)<br />
{ System.out.println(c[x]);}}}
Posted at: Thu Jan 28 06:27:46 2010 (GMT)
|
From: asha_g_mca | Reply 2 of 10 | Reply | View replies (1)
|
Subject: Contributed Answer/Explanation to Q. 1 |
JAVA
class lucky
{
int arr[ ];
public static void display(int q, int n)
{int size=n/q;
int b[ ]= new int[size];
for(int i=0,j=0;j<arr.length;i++,j+=q) b[i]=arr[ j ];
System.out.println("Removing every" +q +"number we
get:");
for(int i=0;i<=b.length;i+=q) System.out.print(b[i]+"
");
System.out.println();
}
public static void main(int n)
{
if (n<50)
{
int q=1;
for(int i=1;i<=n;i++) arr[i]=i;
boolean flag=true;
while(flag)
{
display(q,n);
q++;
if (q>n ) {
flag=false;
break;
}
}
}
else
System.out.println("Enter a number less than 50");
}
}
Posted at: Tue Sep 14 06:56:34 2010 (GMT)
|
From: asha_g_mca | Reply 3 of 10 | Reply | |
Subject: Contributed Answer/Explanation to Q. 1 |
JAVA
class lucky
{
int arr[ ];
public static void display(int q, int n)
{int size=n/q;
int b[ ]= new int[size];
for(int i=0,j=0;j
System.out.println("Removing every" +q +"number we
get:");
for(int i=0;i<=b.length;i+=q) System.out.print(b[i]+"
");
System.out.println();
}
public static void main(int n)
{
if (n<50)
{
int q=1;
for(int i=0;i<n;i++) arr[i]=i+1;
boolean flag=true;
while(flag)
{
display(q,n);
q++;
if (q>n ) {
flag=false;
break;
}
}
}
else
System.out.println("Enter a number less than 50");
}
}
Posted at: Tue Sep 14 06:57:57 2010 (GMT)
|
From: prerit_agarwal | Reply 4 of 10 | Reply | |
Subject: Contributed Answer/Explanation to Q. 1 |
the easier way........
class isc2001
{
public static void main(int n)
{
int i,j=0;
int a[]=new int[n];
int b[]=new int[n/2];
for(i=0;i<n;i++)
a[i]=i+1;
//for(i=0;i<n;i++)
// System.out.println(a[i]);
for(i=0;i<n;i=i+2)
{
b[j]=a[i];
j++;
}
for(i=2;i<n/2;i=i+3)
{
b[i]=0;
}
for(i=0;i<n/2;i++)
{
if(b[i]!=0)
System.out.println(b[i]);
}
}
}
Posted at: Thu Sep 30 16:17:22 2010 (GMT)
|
From: prerit_agarwal | Reply 5 of 10 | Reply | |
Subject: Contributed Answer/Explanation to Q. 1 |
the easier way................
class isc2001
{
public static void main(int n)
{
int i,j=0;
int a[]=new int[n];
int b[]=new int[n/2];
for(i=0;i<n;i++)
a[i]=i+1;
//for(i=0;i<n;i++)
// System.out.println(a[i]);
for(i=0;i<n;i=i+2)
{
b[j]=a[i];
j++;
}
for(i=2;i<n/2;i=i+3)
{
b[i]=0;
}
for(i=0;i<n/2;i++)
{
if(b[i]!=0)
System.out.println(b[i]);
}
}
}
Posted at: Thu Sep 30 16:19:11 2010 (GMT)
|
From: freak7648 | Reply 6 of 10 | Reply | View replies (1)
|
Subject: Contributed Answer/Explanation to Q. 1 |
java class
import java.io.*;
class ques
{
public static void main(String args[])throws IOException
{
InputStreamReader read =new InputStreamReader(System.in);
BufferedReader in =new BufferedReader(read);
System.out.print("Month Number : ");
int m=Integer.parseInt(in.readLine());
System.out.println();
System.out.print("Day : ");
int c=Integer.parseInt(in.readLine());
System.out.println();
System.out.print("Year : ");
int y=Integer.parseInt(in.readLine());
System.out.println();
int y1=y;
int m1=m-1;
int a[]={31,28,31,30,31,30,31,31,30,31,30,31};
int b[]={31,29,31,30,31,30,31,31,30,31,30,31};
int d=0,e;
for (int j=0;j<m1;j++)
{
if (y1%4==0)
{d=d+b[j];}
else
{d=d+a[j];}
}
int d1=d+c;
System.out.print("Corresponding Day Of The Year Is : "+d1);
System.out.println();
System.out.print("(");
for (int j=0;j<m1;j++)
{
if (y1%4==0)
{e=b[j];
System.out.print(e +"+");}
else
{e=a[j];
System.out.print(e +"+");}
}
System.out.print(c+") ="+d1);
System.out.println();
}
}
Posted at: Thu Feb 10 11:31:02 2011 (GMT)
|
From: freak7648 | Reply 7 of 10 | Reply | |
Subject: decor |
the extra loops are to finally facilitate to the ques as demanded
:) Posted at: Thu Feb 10 11:31:57 2011 (GMT)
|
From: ajma | Reply 8 of 10 | Reply | |
Subject: Contributed Answer/Explanation to Q. 3 |
import java.io.*;
Posted at: Mon Feb 17 07:44:12 2014 (GMT)
|
From: ajma | Reply 9 of 10 | Reply | |
Subject: Contributed Answer/Explanation to Q. 3 |
import java.io.*; class sortmerge { int n,m; void sort()throws
IOException { BufferedReader buf=new BufferedReader(new
InputStreamReader(System.in)); System.out.println ( "Enter number of
names in array A"); n=Integer.parseInt(b
<p class="MsoPlainText">
<font face="Courier New">Use can understand this by just
looking</font>
</p>
Posted at: Mon Feb 17 08:05:22 2014 (GMT)
|
From: samprithi | Reply 10 of 10 | Reply | |
Subject: Contributed Answer/Explanation to Q. 2 |
import java.io.*;
public class year
{
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
public void show()throws IOException
{
int month;
System.out.println("Enter the month");
int m=Integer.parseInt(br.readLine());
System.out.println("Enter the day");
int d=Integer.parseInt(br.readLine());
System.out.println("Enter the year");
int y=Integer.parseInt(br.readLine());
if(y%4==0)
{
switch(m)
{
case 01:
month=d;
System.out.println("number of days"+month);
break;
case 02:
month=31+d;
System.out.println("number of days"+month);
break;
case 03:
month=31+29+d;
System.out.println("number of days"+month);
break;
case 04:
month=31+29+31+d;
System.out.println("number of days"+month);
break;
case 05:
month=31+29+31+30+d;
System.out.println("number of days"+month);
break;
case 06:
month=31+29+31+30+31+d;
System.out.println("number of days"+month);
break;
case 07:
month=31+29+31+30+31+30+d;
System.out.println("number of days"+month);
break;
case 8:
month=31+29+31+30+31+30+31+d;
System.out.println("number of days"+month);
break;
case 9:
month=31+29+31+30+31+30+31+d+31;
System.out.println("number of days"+month);
break;
case 10:
month=31+29+31+30+31+30+31+d+31+30;
System.out.println("number of days"+month);
break;
case 11:
month=31+29+31+30+31+30+31+d+31+30+31;
System.out.println("number of days"+month);
break;
case 12:
month=31+29+31+30+31+30+31+d+31+30+31+30;
System.out.println("number of days"+month);
break;
default :
System.out.println("error");
break;
}}
else
{
switch(m)
{
case 01:
month=d;
System.out.println("number of days"+month);
break;
case 02:
month=31+d;
System.out.println("number of days"+month);
break;
case 03:
month=31+28+d;
System.out.println("number of days"+month);
break;
case 04:
month=31+28+31+d;
System.out.println("number of days"+month);
break;
case 05:
month=31+28+31+30+d;
System.out.println("number of days"+month);
break;
case 06:
month=31+28+31+30+31+d;
System.out.println("number of days"+month);
break;
case 07:
month=31+28+31+30+31+30+d;
System.out.println("number of days"+month);
break;
case 8:
month=31+28+31+30+31+30+31+d;
System.out.println("number of days"+month);
break;
case 9:
month=31+28+31+30+31+30+31+d+31;
System.out.println("number of days"+month);
break;
case 10:
month=31+28+31+30+31+30+31+d+31+30;
System.out.println("number of days"+month);
break;
case 11:
month=31+28+31+30+31+30+31+d+31+30+31;
System.out.println("number of days"+month);
break;
case 12:
month=31+28+31+30+31+30+31+d+31+30+31+30;
System.out.println("number of days"+month);
break;
default :
System.out.println("error");
break;
}}
}}
Posted at: Sat Feb 7 08:30:09 2015 (GMT)
|
Page 1 of 1
|