Thursday, 1 June 2017

JAVA Tutorial-1

1. Demonstrate HelloWorld Application with Single and Multiple Main in a java program.

 
   class Hello
   {
     public static void main(String a[])
     {
       System.out.println("Hello Java");
       main();
     }
     public static void main()
     {
       System.out.println("Hello World");
     } 
   }

Output

2. Write a console program to define and initialize a variable of type byte to 1, and then successively multiply it by 2 and display its value 8 times. Explain the reason for the last result.

 
class ByteDemo
{
   public static void main(String ar[])
   {
      byte a=1;
      int i=1;
      while(i<=8)
      { 
         a=(byte)(a*2);
  System.out.println(a);
  i++;
       }
   }
}

Output

Reason : Byte range is -128 to 127, so in this case 64*2=128 but byte range upto 127 so it will starts from -128 that's why last two output is -128 and 0

3. Write a program that defines a floating-point variable initialized with a dollar value for your income and a second floating-point variable initialized with a value corresponding to a tax rate of 35 percent. Calculate and output the amount of tax you must pay with the Rs. and paisa stored as separate integer values (use two variables of type int to hold the tax, perhaps taxRs and taxPaisa).

 
class tax
{
   public static void main(String args[])
   {
 float a,b,rs;
 int taxrs,taxpaisa,t;
 a=(float)200.85;
 b=(float)((35.00*a)/100.00);
 rs=(float)(b*67.50);
 taxrs=(int)rs;
 taxpaisa=(int)((rs-taxrs)*100);
 System.out.println("Tax Rate in Dollars="+b);
 System.out.println("Tax Rate in Rs="+taxrs);
 System.out.println("Tax Rate in Paisa="+taxpaisa);
   }
}

Output

4. Write a program that calculate percentage marks of the student if marks of 6 subjects are given.

 
class marks
{
   public static void main(String args[])
   {
 int ma=50,java=60,mp=66,sp=65,ada=65,dbms=70;
 float per;
 System.out.println("Subject Marks");
 System.out.println("Math="+ma);
 System.out.println("java="+java);
 System.out.println("mp="+mp);
 System.out.println("sp="+sp);
 System.out.println("ada="+ada);
 System.out.println("dbms="+dbms);
 per=(float)(((ma+java+mp+sp+ada+dbms)*100)/600);
 System.out.println("Percentage="+per);
   }
}

Output

Share:

Related Posts:

  • JAVA Tutorial-3 Create an array of String variables and initialize the array with the names of the months from January to December. Create an array containing 12 random decimal values bet… Read More
  • JAVA Tutorial-2 Write a program to display a random choice from a set of six choices for breakfast (you could use any set; for example, scrambled eggs, waffles, fruit, cereal, toast, or … Read More
  • JAVA Tutorial-4 Program 1 Program 2 Program 3 Program 4 Program 5 1. create a class called student having data member like name,enr,branch,city,spi define construct which can ini d… Read More
  • JAVA-Concept Wise Program Program List Class Program Stack Program Recursion Method Overloading Constructor & Constructor Overloading This Keyword Static variable, Static Method & Static Bloc… Read More
  • JAVA Tutorial-5 Program 1 Program 2 Program 3 Program 4 Program 5 Program 6 1. The abstract Vegetable class has three subclasses named Potato, Brinjal and Tomato. Write an applica… Read More

2 comments:

  1. great job man!
    so did you you passout from marwadiuniversity ?

    ReplyDelete
  2. you are making your work easier man thanku for this assignmnet brooo

    ReplyDelete