0% found this document useful (0 votes)
3 views5 pages

java file

The document contains a series of Java programming exercises, each demonstrating different functionalities such as printing a name, calculating the sum of two numbers, computing the area of a circle, and determining simple interest. It also includes programs to check if a number is even or odd, identify leap years, print multiplication tables, and calculate factorials. Each program is accompanied by example outputs illustrating the expected results.

Uploaded by

aryafireplaz
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views5 pages

java file

The document contains a series of Java programming exercises, each demonstrating different functionalities such as printing a name, calculating the sum of two numbers, computing the area of a circle, and determining simple interest. It also includes programs to check if a number is even or odd, identify leap years, print multiplication tables, and calculate factorials. Each program is accompanied by example outputs illustrating the expected results.

Uploaded by

aryafireplaz
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1. Write a program to print your name.

Import [Link];

public class Main

public static void main(String[] args) {

[Link]("My name is:" + "sachin pandey");

OUTPUT - My name is: sachin pandey

2. Write a program to print sum of two number.

import [Link];

public class SumOfTwoNumbers {


public static void main(String[] args) {

Scanner sc = new Scanner([Link]);


[Link]("Enter first number: ");
int num1 = [Link]();

[Link]("Enter second number: ");


int num2 = [Link]();

int sum = num1 + num2;

[Link]("Sum = " + sum);


}
}

OUTPUT- Enter first number: 2


Enter second number: 3
Sum = 5

3. Write a program to print area of circle

import [Link];

public class AreaOfCircle {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

[Link]("Enter radius: ");


double radius = [Link]();

double area = 3.14* radius * radius;

[Link]("Area of Circle = " + area);


}
}

OUTPUT - Enter radius: 2


Area of Circle = 12.56

4. Write a program to print the simple interest

import [Link];

public class SimpleInterest {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

[Link]("Enter Principal: ");


double p = [Link]();

[Link]("Enter Rate: ");


double r = [Link]();

[Link]("Enter Time: ");


double t = [Link]();

double si = (p * r * t) / 100;

[Link]("Simple Interest = " + si);


}
}

OUTPUT - Enter Principal: 1000


Enter Rate:2
Enter Time:2
Simple Interest =40
5. Write a program to check given number is even or odd

import [Link];

public class OddEven {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

[Link]("Enter a number: ");


int num = [Link]();

if (num % 2 == 0) {
[Link]("Even Number");
}
else {
[Link]("Odd Number");
}
}
}

OUTPUT - Enter a number:2


Even Number

6. Write a program to check the given number is leap year or not

import [Link];

public class LeapYear {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

[Link]("Enter year: ");

int year = [Link]();

if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {

[Link]("Leap Year");

}
else {

[Link]("Not a Leap Year");

OUTPUT - Enter year: 2056


Leap Year

7. Write a program to print the table of a given number

import [Link];

public class Table {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

[Link]("Enter a number: ");


int num = [Link]();

for (int i = 1; i <= 10; i++) {


[Link](num + " x " + i + " = " + (num * i));
}
}
}

OUTPUT - Enter a number: 2

2x1=2

2x2=4

2x3=6

2x4=8

2 x 5 = 10

2 x 6 = 12

2 x 7 = 14

2 x 8 = 16

2 x 9 = 18
2 x 10 = 20

8. Write a program to print factorial of given no.

import [Link];

public class Factorial {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

[Link]("Enter a number: ");


int num = [Link]();

int fact = 1;

for (int i = 1; i <= num; i++) {


fact = fact * i;
}

[Link]("Factorial = " + fact);


}
}

OUTPUT - Enter a number: 4

Factorial = 24

9. Write a program for multilevel inheritance

You might also like