Sunday, 30 April 2017

Information Practices (IP for class XI & XII)


Java Programs
BASIC PROGRAMS


1. Creating hello java example

class Simple{

public static void main(String args[]){

System.out.println("Hello Java");

}
}


save this file as Simple.java

To compile:javac Simple.java
To execute:java Simple
Output:
Hello Java

SAMPLE QUESTION PAPER WITH SOLUTION
1 . Write a Program to calculate charges for sending particles when the charges are as follows
For the ¸rst 1KG Rs.15.00 , For additional weight , for every 500gm or fraction thereof: Rs 8.00
Ans
class Prog1
{
static void test(double wt)//user enters the weight in KGs
{
   System.out.println(“Parcel Weight is “+wt);
   int icharge = 15;
   System.out.println(“Initial charge is “+icharge);
   
   int rwt = (int)((wt-1)*1000);
   System.out.println(“Remaining weight after deducing 1Kg “+rwt);

   int rcharge = (rwt/500)*8;
   System.out.println(“Charge excluding fractional part is Rs.”+(icharge+rcharge));

   int fcharge = (rwt%500>0)?8:0;
   System.out.println(“Charge for fractional part is Rs. “+fcharge);

   int tcharge = icharge+rcharge+fcharge;
   System.out.println(“Total Charge is Rs. “+tcharge);
}
}
2 . A special two-digit number is such that when the sum of its digits is added to the product of
its digits , the result is equal to original number
Example : 59
5+9 = 14
5*9 = 45
45+14 = 59 Therefore , 59 is a special two digit number
Write a program in java to check whether a number is special two-digit number or not
Ans
class Prog2
{
static void test(int num)//user inputs a two-digit number
{
  int m = num;
  int product = 1;
  int sum = 0;
  while(m>0)
  {
   int dig = m%10;
   sum = sum+dig;
   product = product*dig;
   m/=10;
  }
   int nalsum = sum+product;
   if(nalsum==num)
      System.out.println(num+” is a special two digit number “);
   else
     System.out.println(num+ ” is not a special two digit number “);
}
}
3.Write a Java Program to accept a month using Scanner class , and display the number of days
present in that month
Ans :
import java.util.*;
class Prog3
{
static void test()
{
   Scanner in = new Scanner(System.in);
   System.out.println(“Enter the number of month “);
   int choice = in.nextInt();
   switch(choice)
   {
     case 1:
     case 3:
     case 5:
     case 7:
     case 8:
     case 10:
     case 12:
             System.out.println(“No. of days are 31 days “);
             break;
     case 4:
     case 6:
     case 9:
     case 11:
            System.out.println(“No .days are 30 days “);
            break;
     case 2:
            System.out.println(“No. Of days are 28 or 29 “);
            break;
     default : System.out.println(“Wrong Choice “);
}
}
}

4.Write a program to display the following pattern :
1 3 5 7 9
3 5 7 9 1
5 7 8 1 3
7 9 1 3 5
9 1 3 5 7
Ans
class Program4
{
static void teja()
{
    for(int i = 1,l=1;i<=5;i++,l+=2)
    {
      int k = 1;
      for(int j = 1,m=l;j<=5;j++,m+=2)
      {
       if(m>9)
       {
         System.out.print(k+” “);
         k+=2;
       }
       else
          if(l==5&&m==9)
          {
            System.out.print(“8 “);
           }
          else
           System.out.print(m+” “);
       }
        System.out.println();
       }
}
}
5.Write a Program in java to obtain the ¸rst eight numbers of the following series :
1,11,111,1111………………
class Prog5
{
static void test()
{
 double s=0.0;
 int p;
 for(int i = 0;i<=7;i++)
 {
     s=s+Math.pow(10,i);
     p = (int)s;
     System.out.print(p+” , “);
 }
}
}
Section – B
Answer any Four
1.Java language provides various ways to get the data value within a program. Compare the way
of using Command line argument with the way of using Input Stream
Ans
1.To take the input through the Input Stream method , ‘java.io’ package should be imported as
the Input Stream is de¸ned in that package whereas no package is needed to be imported to
take the input using Command Line Method
2.To take the input through the Input Stream Method , two classes , namely (i)
InputStreamReader , and (ii) BufferedReader
whereas in Command Line method no class is needed to be declared.
2.Explain the following Math functions with their output by taking -8.76 as input
(i)Math.Floor()
Ans : Math.Floor(-8.76) returns in a double type value -9.0 , as
-9.0 is the next lowest number to -8.76
(ii)Math.ceil()
Ans:Math.ceil(-8.76) returns in a double type value -7.0 , as
-7.0 is the next highest number to -8.76
3.What is the Syntax for :
(i)for loop
Ans :
for(initial value ; test condition ; step value)
{
Body of the loop
}
(ii)do….while loop
Ans :
Initial value
do
{
body of the loop
step value;
}
while(test condition);
4.What are the differences between if …else and switch…case ?
Ans :
1.If…else results in a Boolean type value whereas switch…case returns in a value of int or char
datatypes
2.If..else can also perform tests on Logical operations whereas switch…case can only perform
test for equality
3.If…else Can perform the test for Strings also whereas switch…case cannot perform tests on
String values
4.Default statement is applied in switch..case whereas it is not applied in if…else
5.What are the differences between Entry controlled loop and exit controlled loop ?
Ans :
1.Entry controlled loop is while loop whereas exit controlled loop is do…while loop
2.Do…while loop will execute at least once , even if the condition is not satis¸ed whereas while
loop will never execute if the condition is not satis¸ed
3.While loop will check the condition ¸rst and then will execute the block whereas do…while
loop will execute the block ¸rst and the check the condition
Section – C
Fill in the blanks
1 . _________ is the process in which a program is validated and _________ is the process in
which the errors in the program are removed
Ans : (i)Testing , (ii) Debugging
2.The ___________ is a selective structure where several possible constant values are checked
for specific value
Ans : Switch case
3.A Java Program executes but doesn’t give the desired output and will not terminate from the
terminal window . Then this is a ______________ error in the program
Ans:Logical Error
4 . A __________ statement in a Java Programming is enclosed in braces
Ans : Compound Statement
5.Generally , for the fixed iterations ________ loop can be used and for the variable iterations
_________ loop can be used.
Ans : (i) for loop , (ii) while loop (or) do-while loop




























- CBSE
- CBSE Curriculum, CBSE study material, CBSE XI sample papers, CBSE XI previous year question papers
- CBSE textbooks , CBSE books download, CBSE XII sample papers, CBSE XII previous year question papers,
- CBSE IX sample papers , CBSE X sample papers , CBSE X previous year papers, CBSE syllabus, CBSE classes
- CBSE Computer Sc Question papers, CBSE model papers, CBSE coaching in Govindpuram, Ghaziabad.
- C++ Classes, JAVA Classes,  C#.NET classes
- C++ in Govindpuram, C++ Coaching in Govindpuram, C++ Tuition in Govindpuram, C++ Classes in Govindpuram
- JAVA in Govindpuram, JAVA Coaching in Govindpuram, JAVA Tuition in Govindpuram, JAVA Classes in Govindpuram
- C#.NET in Govindpuram, C#.NET Coaching in Govindpuram, C#.NET Tuition in Govindpuram, C#.NET Classes in Govindpuram
- English Speaking in Govindpuram, English Speaking Coaching in Govindpuram, English Speaking Tuition in Govindpuram, English Speaking Classes in Govindpuram
- Spoken English in Govindpuram, Spoken English Coaching in Govindpuram, Spoken English Tuition in Govindpuram, Spoken English Classes in Govindpuram
- C++ in Ghaziabad, C++ Coaching in Ghaziabad, C++  Tuition in Ghaziabad, C++ Classes in Ghaziabad
- JAVA in Ghaziabad, JAVA Coaching in Ghaziabad,  JAVA Tuition in Ghaziabad, JAVA Classes in Ghaziabad
- C#.NET in Ghaziabad, C#.NET Coaching in  Ghaziabad, C#.NET Tuition in Ghaziabad, C#.NET Classes in Ghaziabad
- English Speaking in Ghaziabad, English Speaking Coaching in Ghaziabad, English Speaking Tuition in Ghaziabad, English Speaking Classes in Ghaziabad
- Spoken English in Ghaziabad, Spoken English Coaching in Ghaziabad, Spoken English Tuition in Ghaziabad, Spoken English Classes in Ghaziabad
- C++ training in Govindpuram, C++ institute in Govindpuram, C++ jobs in Govindpuram, C++ center in Govindpuram
- C++ training in Ghaziabad, C++ institute in Ghaziabad, C++ jobs in Ghaziabad, C++ center in Ghaziabad
- JAVA training in Govindpuram, JAVA institute in Govindpuram, JAVA jobs in Govindpuram, JAVA center in Govindpuram
- JAVA training in Ghaziabad, JAVA institute in Ghaziabad, JAVA jobs in Ghaziabad, JAVA center in Ghaziabad
- C#.NET training in Govindpuram, C#.NET institute in Govindpuram, C#.NET jobs in Govindpuram, C#.NET center in Govindpuram
- C#.NET training in Ghaziabad, C#.NET institute in Ghaziabad, C#.NET jobs in Ghaziabad, C#.NET center in Ghaziabad


- english speaking course in ghaziabad, english speaking course in ghaziabad,english speaking course in ghaziabad, utter pradesh,english speaking course in ghaziabad,english speaking course in ghaziabad,

No comments:

Post a Comment