number 1
स्कैनर क्लास का उपयोग करके के बोर्ड से इनपट
ु लेना और प्रिंट करना
import [Link];
public class Main {
public static void main(String[ ] args) {
Scanner s = new Scanner([Link]);
[Link]("enter your name ");
String input = [Link]();
[Link]("inter your age " + input);
Int age = [Link]();
[Link](“name”+ name);
[Link](“Age + age);
[Link]();
}
}
Number .2
जावा का प्रोग्राम triangle में स्टार प्रिंट करने के लिए
import [Link];
public class TrianglePattern {
public static void main(String[ ] args) {
Scanner scanner = new Scanner([Link]);
[Link]("inter your raw number");
int rows = [Link]();
for (int i = 1; i <= rows; i++) {
for (int j = rows - i; j > 0; j--) {
[Link](" ");
}
for (int k = 1; k <= (2 * i - 1); k++) {
[Link]("*");
}
[Link]();
}
[Link]();
}
}
Number .3
public class HelloWorld {
public static void main(String[ ] args) {
[Link]("Hello, World!");
}
}
Number .4
जावा का प्रोग्राम क्लास और ऑबजेक्ट का प्रयोग करके चतर्भु
ु ज का एरिया निकालने के लिए।
import [Link];
class Quadrilateral {
private double length;
private double width;
public Quadrilateral(double length, double width) {
[Link] = length;
[Link] = width;
}
public double calculateArea() {
return length * width;
}
}
public class Main {
public static void main(String[ ] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter the length of the quadrilateral: ");
double length = [Link]();
[Link]("Enter the width of the quadrilateral: ");
double width = [Link]();
Quadrilateral quadrilateral = new Quadrilateral(length, width);
double area = [Link]();
[Link]("The area of the quadrilateral is: " + area);
[Link]();
}
}
Number .5
inheritance car example java program me
class Animal {
public void sound() {
[Link]("Animals make sounds.");
}
}
class Dog extends Animal {
public void bark() {
[Link]("Dog barks.");
}
public void sound() {
[Link]("Dog makes a barking sound.");
}
}
public class InheritanceExample {
public static void main(String[] args) {
Dog myDog = new Dog();
[Link]();
[Link]();
}
}
Output
Dog makes a barking sound.
Dog barks.
Number 6
जावा का प्रोग्राम क्लास का ऊपयोग
class Rectangle {
private double length;
private double width;
public Rectangle(double length, double width) {
[Link] = length;
[Link] = width;
}
public double calculateArea() {
return length * width;
}
public double calculatePerimeter() {
return 2 * (length + width);
}
}
public class Main {
public static void main(String[ ] args) {
Rectangle myRectangle = new Rectangle(5, 3);
[Link]("Area of the rectangle: " + [Link]());
[Link]("Perimeter of the rectangle: " + [Link]());
}
}
Output
Area of the rectangle: 15.0
Perimeter of the rectangle: 16.0
Number .7
जावा का प्रोग्राम मेथड ओवेरलोडिंग
class MathOperations {
public int add(int a, int b) {
return a + b;
}
public int add(int a, int b, int c) {
return a + b + c;
}
}
public class Main {
public static void main(String[] args) {
MathOperations maths = new MathOperations();
int sum1 = [Link](5, 10);
[Link]("Sum of 5 and 10 is: " + sum1);
int sum2 = [Link](5, 10, 15);
[Link]("Sum of 5, 10, and 15 is: " + sum2);
}
}
Output
Sum of 5 and 10 is: 15
Sum of 5, 10, and 15 is: 30
Number . 8
जावा का प्रोग्राम फ्लोटिङ पॉईंट नंबर कोप multiply करने के लिए
import [Link];
public class MultiplyFloats {
public static void main(String[ ] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter the first floating-point number: ");
float num1 = [Link]();
[Link]("Enter the second floating-point number: ");
float num2 = [Link]();
float product = num1 * num2;
[Link]("The product of " + num1 + " and " + num2 + " is: " + product);
[Link]();
}
}
Output
Enter the first floating-point number: 3.5
Enter the second floating-point number: 2.2
The product of 3.5 and 2.2 is: 7.7
Number. 9
Java Program to demonstrate Working of Method
import [Link];
class Calculator {
public int add(int a, int b) {
return a + b;
}
public int subtract(int a, int b) {
return a - b;
}
public int multiply(int a, int b) {
return a * b;
}
public double divide(int a, int b) {
if (b != 0) {
return (double) a / b;
} else {
[Link]("Division by zero is not allowed.");
return 0;
}
}
}
public class Main {
public static void main(String[ ] args) {
Scanner scanner = new Scanner([Link]);
Calculator calculator = new Calculator();
[Link]("Enter the first number: ");
int num1 = [Link]();
[Link]("Enter the second number: ");
int num2 = [Link]();
[Link]("Addition of " + num1 + " and " + num2 + " is: " + [Link](num1,
num2));
[Link]("Subtraction of " + num1 + " and " + num2 + " is: " +
[Link](num1, num2));
[Link]("Multiplication of " + num1 + " and " + num2 + " is: " +
[Link](num1, num2));
[Link]("Division of " + num1 + " by " + num2 + " is: " + [Link](num1,
num2));
[Link]();
}
}
Output
Enter the first number: 10
Enter the second number: 5
Addition of 10 and 5 is: 15
Subtraction of 10 and 5 is: 5
Multiplication of 10 and 5 is: 50
Division of 10 by 5 is: 2.0