Showing posts with label 2006. Show all posts
Showing posts with label 2006. Show all posts

Wednesday, 11 March 2015

[JAVA] [ICSE 2006 Answer 6] Replacing Words

Question:
ICSE 2006 Question 6
Consider the following statement-
"January 26 is celebrated as the Republic Day of India".
Write a program to change 26 to 15, January to August, Republic to Independence and finally print "August 15 is celebrated as the Independence Day of India".

Source Code:
public class ICSE2006_6
{
    public static void main()throws Exception
    {
        String s="January 26 is celebrated as the Republic Day of India";
        s=s.replace("January", "August");
        s=s.replace("26", "15");
        s=s.replace("Republic", "Independence");
        System.out.println(s);
    }
}


Result:
OUTPUT:
August 15 is celebrated as the Independence Day of India

[JAVA] [ICSE 2006 Answer 5] Calculating Bill Amount

Question:
ICSE 2006 Question 5
A cloth showroom has announced the following festival discounts on the purchase of items, based on the total cose of the items puchased:
TOTAL COST                   DISCOUNT
Less than Rs.2,000                 5%
Rs.2,001 to Rs.5,000              25%
Rs.5,001 to Rs.10,000             35%
Above Rs.10,000                   50%
Write a program to input the total cost and to compute and display the amount to be paid by the customer after availing the discount.

Source Code:
public class ICSE2006_5
{
    public static void main(double cost)throws Exception
    {
        int discount=0;
        if(cost<=2000)
            discount=5;
        else if(cost<=5000)
            discount=25;
        else if(cost<=10000)
            discount=35;
        else
            discount=50;
        System.out.println("The cost to be paid by the customer after availing the discount of "+discount+"% is Rs. "+(cost*(100-discount)/100)+".");
    }
}


Result:
INPUT:
5901.45
OUTPUT:
The cost to be paid by the customer after availing the discount of 35% is Rs. 3835.9425.

[JAVA] [ICSE 2006 Answer 4] Conditional Sum Finding

Question:
ICSE 2006 Question 4
Write a program to calculate and print the sum of odd numbers and the sum of even numbers for the first n natural numbers.
The integer n is to be entered by the user

Source Code:
public class ICSE2006_4
{
    public static void main(int n)throws Exception
    {
        int sumo=0, sume=0;
        for(int i=1; i<=n; i++)
            if(i%2==0)
                sume+=i;
            else
                sumo+=i;
        System.out.println("The sum of odd numbers is "+sumo+".\nThe sum of even numbers is "+sume+".");
    }
}


Result:
INPUT:
28
OUTPUT:
The sum of odd numbers is 196.
The sum of even numbers is 210.