SOLUTIONS

TRY YOURSELF:8
/*Program to print odd numbers between 1 and 20 using for loop*/
PROGRAM:
public class ListoddNumbers
 {
        public static void main(String[] args)  
         {
                int limit = 20;    
                System.out.println("Printing ODD numbers between 1 and " + limit);
                for(int i=1; i <= limit; i++) 
                 {
               // if the number is divisible by 2 then it is even
                      if( i % 2 == 1)
                     {
                                System.out.print(i + " ");
                      }
                }
        }
}
Sample Output:
1 2 3 4 5 6 7.......,20 
TRY YOURSELF:7
1)Verify the program with your own concepts.


TRY YOURSELF:6
/*PROGRAM TO PERFORM ARITHMATIC OPERATION USING SWITCH STATEMENTS*/
 
import.java.io.*; 
class month 
{
    public static void main(String[] args)
      {
        double a=10,b=2,c,opt=3;
        switch (opt) 
        {            
            case 1: c=a+b; System.out.println(+c); break;
            case 2: c=a-b; System.out.println(+c); break;
            case 3: c=a*b; System.out.println(+c); break;
            case 4: c=a/b; System.out.println(+c); break;
        }
    }
}

Sample output:
20


TRY YOURSELF:5

/*Program to whether the Arun is eligible to vote age limit to vote must be 18 years,use if else statement and display his eligibility.*/

import.java.io.*;
public class divisor
{
public static void main(String[] args)
{
         int age=18;
         if ( age>=18 )
         {
               System.out.println("ELIGIBLE TO VOTE");
         }
         else
         {
               System.out.println("UN ELIGIBLE TO VOTE");
         }
}
Sample output:

ELIGIBLE TO VOTE
 

TRY YOURSELF:4

  /*Program to calculate your shopping expense.Imagine that you have took Rs.1000 for shopping and calculate how much you money you saved by purchasing the items in that shop.Find out your total expense and your balance amount with you*/

import java.io.*;
class shopping
{
         public static void main(string args[ ])
         {
              double amttook=1000,amtspent;
              double mrpitem1=200,selprice1=180,mrpitem2=100,selprice2=70;
              amtsaved=(mrpitem1-selprice1)+(mrpitem2-selprice2);
              totexpense= selprice1+selprice2;
              balonhand=totexpense-amttook;
              system.out.print("TOTAL EXPENSE="+totexpense);
              newline();
              system.out.print("AMOUNT SAVED="+amtsaved);
              newline();
              system.out.print("AMOUNT ON YOUR HAND="+balonhand);
         }

                           
SAMPLE OUTPUT:     

TOTAL EXPENSE  =250
AMOUNT SAVED  =50
AMOUNT ON YOUR HAND=750





  TRY YOURSELF:3

/*Solution for the program to find square root of the number(decimal).*/

 PROGRAM: 
import java.io.*;
import java.lang.math*;
class square
{
         public static void main(string args[ ])
         {
               float x=55.65,y;
                y=math.sqrt(x);
                system.out.println("SQUARE ROOT="+y);
          }
}
SAMPLE OUTPUT:
SQUARE ROOT=7.4598


TRY YOURSELF-2
 /* SOLUTION FOR PROGRAM TO FIND SIMPLE INTEREST*/

import java.io.*;
class interest
{
   public static void main(string args[ ])
   {
     int p=10,n=20,r=50;
     float si;
     si=(p*n*r)/100;
     system.out.println("interest is="+si);
    }
}

TRY YOURSELF-1
/* SOLUTION FOR PROGRAM TO PRINT YOUR NAME AND ADDRESS IN SEPARATE LINES*/

class Welcome
{
        public static void main(String args[])
            {
              system.out.println(" HARI "); 

              system.out.println(" INDIA");

            }
}

SAMPLE OUTPUT:

HARI
INDIA

No comments:

Post a Comment

Animated Social Gadget - Blogger And Wordpress Tips