0% found this document useful (0 votes)
2 views4 pages

Asm 249425

The document provides a series of Java programming exercises that cover various basic concepts such as calculating profit, swapping variables, displaying bio-data, calculating shares, pendulum time period, unit conversion, and tax computation. Each exercise includes a code snippet and the expected output. The examples are designed to help beginners understand fundamental programming techniques in Java.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Asm 249425

The document provides a series of Java programming exercises that cover various basic concepts such as calculating profit, swapping variables, displaying bio-data, calculating shares, pendulum time period, unit conversion, and tax computation. Each exercise includes a code snippet and the expected output. The examples are designed to help beginners understand fundamental programming techniques in Java.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

INTRODUCTION TO JAVA

1. Write a program using variables to find the profit and profit percent of a certain transaction where S.P.=₹ 10000
and C.P.=₹ 7000.

class Profit
{
static void main()
{
float sp=10000,cp=7000,p,pp;
p=sp-cp;
pp=p/cp*100;
System.out.println("Profit="+p);
System.out.println("Profit Percent="+pp);
}
}

Output

2.Write a program to initialize two integer variables a and b with 5 and 6 respectively and interchange them. Thus
after interchanging, a and b will be 6 and 5 respectively.
class Swap
{
static void main()
{
int a=5,b=6,t;
t=a;
a=b;
b=t;
System.out.println(a+" "+b);
}
}

Output

3.You want to display your bio-data on the output screen. Write a program in Java to perform the task in the given
format:
Name:
Father's Name:
Date of birth:
Blood Group:
Aadhar Card No.:
State:
class BioData {
public static void main() {
System.out.println("Name: Tiffany Holland");
System.out.println("Father's Name:Tom Holland");
System.out.println("Date of birth: 12/12/2005");
System.out.println("Blood Group: O+");
System.out.println("Aadhar Card No.: 4321 8756 9978");
System.out.println("State: West Bengal");
}
}

Output

4.A businessman wishes to accumulate 3000 shares of a company. However, he already has some shares of that
company valuing ₹10 (nominal value) which yield 10% dividend per annum and receive ₹2000 as dividend at the end
of the year. Write a program in Java to calculate the number of shares he has and how many more shares to be
purchased to make his target.
Hint: No. of share = (Annual dividend * 100) / (Nominal value * div%)

public class Shares


{
public static void main() {
int sharesHeld = (2000 * 100)/(10 * 10);
System.out.println("No. of shares held currently = "
+ sharesHeld);
int sharesRequired = 3000 - sharesHeld;
System.out.println("No. of shares to purchase = "
+ sharesRequired);
}
}
Output

5.The time period of a Simple Pendulum is given by the formula:


T = 2π√(l/g)
Write a program to calculate the time period of a Simple Pendulum by assuming length to be 0.75 and acceleration
due to gravity (g) as 9.8.

public class SimplePendulum


{
public static void main() {
double l = 0.75;
double g=9.8;
double t = 2 * (22.0 / 7.0) * Math.sqrt(l/g);
System.out.println("T = " + t);
}
}
Output

6.Write a program to calculate the distance of 1506 feet in terms of yards and miles.
Given Fixed values are 1 mile=1760 yards and 1 yard=3 feet.

public class Conversion


{
public static void main()
{
final double yard=3.0;
final double mile=1760;
double df=1056,dm=0,dy=0;
dy=df/yard;
dm=dy/mile;
System.out.println("1056 feet are equal to"+dy+"yards");
System.out.println("1056 feet are equal to"+dm+"miles");
}
}
Output

7.Write a program to calculate tax for a taxable income of Rs.3,10,000, if tax rate is fixed at 2.2%.

public class Calculate


{
public static void main()
{
double taxrate=2.2;
double income=310000,tax=0;
tax=income*taxrate/100;
System.out.println("Tax payable is Rs."+tax);
}
}
Output

8.Write a program that computes tax for income of Rs.12,23,423.The income upto Rs 30,0000 is not taxable and the
tax is computed as 15% of the taxable income.

public class TaxCalc


{
public static void main()
{
double income=1223423;
double taxable=income-300000;
double tax=taxable*0.15;
System.out.println("For income of Rs"+income+"tax payable is Rs."+tax);
}
}
Output

You might also like