Complete IIT AIEEE ICSE ISC PMT help forum
This is a free help Forum for Indian Students.
Complete IIT AIEEE ICSE ISC PMT help forum

Complete help forum for students preparing for icse iit aieee cbse pmt and other related exams.Stay updated about all 2011 exams.
 
HomeHome  PortalPortal  FAQFAQ  SearchSearch  RegisterRegister  MemberlistMemberlist  UsergroupsUsergroups  Log in  India NewsIndia News  
Keywords
YEAR RESULT 2010 CLASS
Latest topics
Top posters
abhas
 
Anu..i luv icse...:)
 
G-7
 
siya
 
Candy
 
jOhNy
 
Apurva
 
WinRrule
 
ambili
 
saif
 



Search if you can't find it here

Java Programs

View previous topic View next topic Go down
AuthorMessage
WinRrule
Active member
Active member
avatar


PostSubject: Java Programs Fri Mar 05, 2010 9:55 am

Hey Guys all the java programs that we need to know for ISC 2010 will be posted here.. some theory notes too will be posted..!
Back to top Go down
View user profile
WinRrule
Active member
Active member
avatar


PostSubject: Re: Java Programs Fri Mar 05, 2010 9:57 am

Question
Write a Java Program to find the sum of all odd numbers divisible by 7 between -50 and 50.

Program
public class prac2 {
public static void main(String[] args) {
int i;
System.out.println("Odd numbers between -50 and 50 which are divisible by 7: ");
for(i=-49; i<50; i++)
if((i%2) != 0)
if((i%7) == 0)
System.out.println(i);
}
}


Last edited by WinRrule on Fri Mar 05, 2010 10:01 am; edited 1 time in total
Back to top Go down
View user profile
WinRrule
Active member
Active member
avatar


PostSubject: Re: Java Programs Fri Mar 05, 2010 9:57 am

Question
Write a Java Program to accept any three numbers and find biggest among them after confirming that they are not equal to each other. Check whether these three numbers form lengths of sides of a triangle.

Program
import java.io.*;
public class prac3 {
public static void main(String[] args) throws IOException {
InputStreamReader inp = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(inp);
System.out.println("Enter 3 numbers: ");
int a = Integer.parseInt(br.readLine());
int b = Integer.parseInt(br.readLine());
int c = Integer.parseInt(br.readLine());
//Check if they are equal
if(a == b && a == c)
System.out.println("All three values are equal.");
//Find the biggest number
int max = a;
if(b > max)
max = b;
if(c > max)
max = c;
System.out.println("The biggest among "+a+", "+b+", "+c+" is "+max);
//Check if they form the sides of a triangle
if(((a+b) > c) && ((a+c) > b) && ((c+b) > a))
System.out.print("These three values can form a triangle.");
else
System.out.println("These values do not form a triangle.");
}
}


Last edited by WinRrule on Fri Mar 05, 2010 10:02 am; edited 1 time in total
Back to top Go down
View user profile
WinRrule
Active member
Active member
avatar


PostSubject: Re: Java Programs Fri Mar 05, 2010 9:57 am

Question
Write a Java Program to accept a number and perform the following:
i. Check if it is three-digit number.
ii. If it is a three-digit number, check if it is an Armstrong number.

Program
import java.io.*;
public class prac4 {
public static void main(String[] args) throws IOException {
int i, m, n = 0;
InputStreamReader in = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(in);
System.out.println("Enter a number: ");
i = Integer.parseInt(br.readLine());
m = i;
while(m > 0){
n++;
m /= 10;
}
if(n == 3){
//For Armstrong number
if(i == sumd(i))
System.out.println(i+" is an Armstrong number.");
}
}
static int power(int n, int p){
if(p == 0)
return 1;
else
return (n * power(n, p-1));
}
static int sumd(int n){
if(n==0) {
return 0;
}
else
return(power((n%10),3) + sumd(n/10));
}
}


Last edited by WinRrule on Fri Mar 05, 2010 10:03 am; edited 1 time in total
Back to top Go down
View user profile
WinRrule
Active member
Active member
avatar


PostSubject: Re: Java Programs Fri Mar 05, 2010 9:59 am

Question
Write a Java Program to find whether the given number is a palindrome or not.


Program
import java.io.*;
public class prac7 {
public static void main(String[] args) throws IOException {
int n, m, d, s = 0;
InputStreamReader inp = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(inp);
System.out.println("Enter a number: ");
n = Integer.parseInt(br.readLine());
m = n;
while(m > 0){
d = m % 10;
s += d;
m /= 10;
}
if(n == s)
System.out.println("It is a Palindrome number.");
else
System.out.println("It is not a Palindrome number.");
}
}
Back to top Go down
View user profile
WinRrule
Active member
Active member
avatar


PostSubject: Re: Java Programs Fri Mar 05, 2010 10:07 am

Question
Write a program to accept a number and check if it is a prime number.

Program
import java.io.*;
public class prac8 {
public static void main(String[] args) throws IOException {
int n, i, fl = 0;
InputStreamReader inp = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(inp);
System.out.println("Enter a number: ");
n = Integer.parseInt(br.readLine());
for (i = 2; i <= (n/2); ++i){
if((n%i) == 0){
fl = 1;
break;
}
}
if(fl == 0)
System.out.println(n+" is a prime number.");
else
System.out.println(n+" is not a prime number.");
}
}
Back to top Go down
View user profile
WinRrule
Active member
Active member
avatar


PostSubject: Re: Java Programs Fri Mar 05, 2010 10:08 am

Question
Write a Java Program to print numbers from 26 to 50 in form of square matrix of order 5x5 using nested for loops.

Program
public class prac13 {
public static void main(String args[]){
int i, j, k;
for(i = 0, k = 26; i < 5; i++, k++){
for(j = 0; j < 5; j++,k++){
System.out.print(k+" ");
}
k--;
System.out.println();
}
}
}
Back to top Go down
View user profile
WinRrule
Active member
Active member
avatar


PostSubject: Re: Java Programs Tue Mar 16, 2010 8:56 pm

Question
Write a Java program to print numbers in circular matrix.

Program
import java.io.*;
public class circular {
public static void main(String args[])throws IOException
{
int i,j,c=1;
InputStreamReader x=new InputStreamReader(System.in);
BufferedReader y=new BufferedReader(x);
System.out.println("Enter value of N: ");
int n;
n=Integer.parseInt(y.readLine());
int a[][]=new int[n][n];
int r=0,s=n-1;
for(i=0;i<n;i )
{
for(j=r;j<s;j )
{
a[i][j]=c;
c ;
}
for(j=r;j<=s-1;j )
{
a[j][s]=c;
c ;
}
for(j=s;j>=r;j--)
{
a[s][j]=c;
c ;
}
for(j=(s-1);j>r;j--)
{
a[j][i]=c;
c ;
}
r ;
s--;
}
for(i=0;i<n;i )
{
for(j=0;j<n;j )
{
System.out.print(a[i][j]);
System.out.print('\t');
}
System.out.println();
}
}
}


Last edited by WinRrule on Tue Mar 16, 2010 9:23 pm; edited 2 times in total
Back to top Go down
View user profile
G-7
Active member
Active member
avatar


PostSubject: Re: Java Programs Tue Mar 16, 2010 9:05 pm

WinRule..! What is the last question..? lol!
Back to top Go down
View user profile
WinRrule
Active member
Active member
avatar


PostSubject: Re: Java Programs Tue Mar 16, 2010 9:20 pm

its for printing numbers in circular fashion.. i think comment didn' print..!
Back to top Go down
View user profile
RC
Active member
Active member
avatar


PostSubject: Re: Java Programs Wed Mar 17, 2010 10:58 am

class Spiral
{
void main(int n)
{
int a[][]=new int[n][n];int c=1;
for (int i = n-1, j = 0; i > 0; i--, j++)
{
for (int k = j; k < i; k++) a[j][k]=c++;
for (int k = j; k < i; k++) a[k][i]=c++;
for (int k = i; k > j; k--) a[i][k]=c++;
for (int k = i; k > j; k--) a[k][j]=c++;
}
//special case for middle element if N is odd
if (n % 2 == 1) a[(n-1)/2][(n-1)/2]=c++;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++)
System.out.print(a[i][j]+" ");
System.out.println();}
}

}
Back to top Go down
View user profile
G-7
Active member
Active member
avatar


PostSubject: Re: Java Programs Wed Mar 17, 2010 11:03 am

0k...now whts this RC,..?
Back to top Go down
View user profile
WinRrule
Active member
Active member
avatar


PostSubject: Re: Java Programs Wed Mar 17, 2010 11:43 am

Queue


A queue is a FIFO structure and physically it can be implemented as an array or as a linked list. In a FIFO data structure, the first element added to the queue will be the first one to be removed. This is equivalent to the requirement that whenever an element is added, all elements that were added before have to be removed before the new element can be invoked. A queue is an example of a linear data structure.Insertions take place at the rear end and deletions take place at the front end.

Queue Implementation

Theoretically, one characteristic of a queue is that it does not have a specific capacity. Regardless of how many elements are already contained, a new element can always be added. It can also be empty, at which point removing an element will be impossible until a new element has been added again.
When a queue is created as an array, no. of elements is declared before processing. The beginning of the array becomes its front end and the end of the array becomes its rear end. The terms 'front' and 'rear' are used in describing a linear list only when it is implemented as a queue.
Front
stores the no. of first element in the queue and the rear stores the number of last element in the queue. The no. of elements in a queue at any given time can be calculated from the values of the front and rear.
If front=0 then no.of elements = 0.
else no. of elements = front - rear + 1
Linked Queues
Linked queues are the queues having links among its elements.
Variation in Queues
Queues can be used in various forms and ways, depending on program requirements. Two popular variations are:
1) Circular queues
2) Dequeues

Circular Queues are the queues implemented in circle form rather than a straight line. They overcome the problem of unutilised space in linear queues implemented as arrays.

Dequeues (Double-ended queues) are the refined queues in which elements can be added or removed at either end but no in the middle.
Back to top Go down
View user profile
G-7
Active member
Active member
avatar


PostSubject: Re: Java Programs Wed Mar 17, 2010 12:01 pm

thanks WinRule..! This is good...!

Dont we have application of dequeue and circular queue..? Aren't there any changes to the Insertion and Deletion code when it comes to dequeue or circular queue..?

Is my question valid..?
Back to top Go down
View user profile
WinRrule
Active member
Active member
avatar


PostSubject: Re: Java Programs Wed Mar 17, 2010 12:28 pm

In specimen Paper Q12 is actually a program related to deque..! so even i'm not so sure nw.. I will ask my teacher nw..!
Back to top Go down
View user profile
saurav bhowmick




PostSubject: Re: Java Programs Wed Mar 17, 2010 1:00 pm

can u plz tell me how to make a full adder circuit with the help of a half adder circuit? I m a class XI student
Back to top Go down
View user profile
WinRrule
Active member
Active member
avatar


PostSubject: Re: Java Programs Wed Mar 17, 2010 6:01 pm

Back to top Go down
View user profile
WinRrule
Active member
Active member
avatar


PostSubject: Re: Java Programs Thu Mar 18, 2010 2:01 pm

//Question 9 from Specimen Paper
import java.io.*;
public class Alpha
{
String str;
Alpha()
{
}
void readword()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a word: ");
str = br.readLine();
System.out.println("The word entered is "+str);
}
void arrange()
{
char[] s = str.toCharArray();
char t;
for (int i = 0; i < (s.length - 1); i++)
{
for (int j = i+1; j < s.length; j++)
{
if(s[i]>s[j])
{
t=s[i];
s[i]=s[j];
s[j]=t;
}
}
}
str = new String(s);
}
void disp()
{
System.out.print("The word in ascending order is ");
System.out.println(str);
}
public static void main(String[] args) throws IOException
{
Alpha a = new Alpha();
a.readword();
a.arrange();
a.disp();
}
}
Back to top Go down
View user profile
WinRrule
Active member
Active member
avatar


PostSubject: Re: Java Programs Thu Mar 18, 2010 2:02 pm

//Question 10 from Specimen Paper
Question 10
import java.io.*;
public class Combination
{
int n, k, c;
Combination()
{
n=0;
k=0;
}
void read()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("To calculate C(n,k):");
System.out.println("Enter value of 'n': ");
n=Integer.parseInt(br.readLine());
System.out.println("Enter value of 'k': ");
k=Integer.parseInt(br.readLine());
}
int fact(int i)
{
if (i == 1)
return 1;
else if(i > 1)
return (fact(i - 1)*i);
else
return 0;
}
void compute()
{
c=(fact(n))/(fact(k)*fact(n-k));
}
void display()
{
System.out.println("The combination value is "+c);
}
public static void main(String[] args) throws IOException
{
Combination combi=new Combination();
combi.read();
if((combi.k)>(combi.n))
{
System.out.println("Please enter values such that n > k.");
return;
}
combi.compute();
combi.display();
}
}
Back to top Go down
View user profile
WinRrule
Active member
Active member
avatar


PostSubject: Re: Java Programs Thu Mar 18, 2010 2:03 pm

//Question 11 from Specimen Paper
class Personal
{
String Name;
int Pan, acc_no;
double basic_pay;
Personal(String nm, int ac, int p, double bp)
{
Name = nm;
Pan = p;
acc_no = ac;
basic_pay = bp;
}
void display()
{
System.out.println("Employee name: "+Name);
System.out.println("Employee PAN number: "+Pan);
System.out.println("Employee basic salary: "+basic_pay);
System.out.println("Employee bank account number: "+acc_no);
}
}
class Retire extends Personal
{
int Yrs;
double Pf, Grat;
Retire(String nm, int ac, int p, double bp, int y, double pro, double gr) {
super(nm, ac, p, bp);
Yrs = y;
Pf = pro;
Grat = gr;
}
void provident()
{
Pf = (0.02 * basic_pay) * Yrs;
}
void gratuity()
{
Grat = (Yrs>=10)?(12*basic_pay):0;
}
void display1()
{
display();
System.out.println("Years of service: "+Yrs);
System.out.println("Provident fund: "+Pf);
System.out.println("Gratuity amount: "+Grat);
}
}
Back to top Go down
View user profile
WinRrule
Active member
Active member
avatar


PostSubject: Re: Java Programs Thu Mar 18, 2010 2:04 pm

//Question 12 from Specimen Paper
public class Chain
{
int[] ele = new int[50];
int cap, front, rear, n;
Chain(int max)
{
cap = max;
front = rear = 0;
ele = new int[cap];
n = 0;
}
void pushfront(int v)
{
if(front==0)
front = cap;
ele[--front] = v;
n++;
}
int popfront()
{
int temp = ele[front++];
if(front == cap)
front = 0;
n--;
return temp;
}
void pushrear(int v)
{
if(rear == cap-1)
rear = 0;
ele[++rear] = v;
n++;
}
int poprear()
{
int temp = ele[rear--];
if(rear == 0)
rear = cap - 1;
n--;
return temp;
}
}
The common name of the entity is Dequeue (Double-ended queue).
Back to top Go down
View user profile
WinRrule
Active member
Active member
avatar


PostSubject: Re: Java Programs Thu Mar 18, 2010 10:09 pm

ISC 2010 Specimen Paper for computer science fully solved
http://www.scribd.com/doc/28594958/Specimen-Paper-CSc-Solved


Last edited by WinRrule on Fri Mar 19, 2010 10:11 am; edited 1 time in total
Back to top Go down
View user profile
WinRrule
Active member
Active member
avatar


PostSubject: Re: Java Programs Fri Mar 19, 2010 9:55 am

//To convert from different number systems
public class convert_nos {
public void hex_to_dec() throws IOException{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the decimal value:");
String hex = bf.readLine();
int i = Integer.parseInt(hex);
String by = Integer.toBinaryString(i);
System.out.println("Binary: " + by);
}
public void bin_To_dec() throws IOException{
BufferedReader bf= new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the Binary value: ");
String str = bf.readLine();
long num = Long.parseLong(str);
long rem;
while(num > 0){
rem = num % 10;
num = num / 10;
if(rem != 0 && rem != 1){
System.out.println("This is not a binary number.");
System.out.println("Please try once again.");
System.exit(0);
}
}
int i= Integer.parseInt(str,2);
System.out.println("Decimal:="+ i);
}
public void dec_to_bin() throws IOException{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the decimal value:");
String hex = bf.readLine();
int i = Integer.parseInt(hex);
String by = Integer.toBinaryString(i);
System.out.println("Binary: " + by);
}
public void dec_to_hex() throws IOException{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the decimal value:");
String hex = bf.readLine();
int i = Integer.parseInt(hex);
String hex1 = Integer.toHexString(i);
System.out.println("Hexa decimal: " + hex1);
}
public void dec_to_oct() throws IOException{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the decimal value:");
String hex = bf.readLine();
int i = Integer.parseInt(hex);
String hex1 = Integer.toHexString(i);
System.out.println("Hexa decimal: " + hex1);
}
public void oct_to_dec() throws IOException{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the octal number:");
String oct = reader.readLine();
int i= Integer.parseInt(oct,Cool;
System.out.println("Decimal:=" + i);
}
}
Back to top Go down
View user profile
Sponsored content




PostSubject: Re: Java Programs

Back to top Go down

Java Programs

View previous topic View next topic Back to top
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
Complete IIT AIEEE ICSE ISC PMT help forum :: ISC :: ISC 2010 [Class xii] :: Computer-