[Go to site: main page, start]

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

Basics Java Program

The document contains 10 simple Java programs designed for beginners, each with a clear aim. Programs include printing 'Hello World', adding two numbers, finding the largest of two or three numbers, checking even or odd numbers, calculating factorials, generating Fibonacci series, reversing a number, checking for palindromes, and demonstrating class and object in OOP. Each program is accompanied by its respective code and a brief explanation of its purpose.

Uploaded by

desix88776
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 views6 pages

Basics Java Program

The document contains 10 simple Java programs designed for beginners, each with a clear aim. Programs include printing 'Hello World', adding two numbers, finding the largest of two or three numbers, checking even or odd numbers, calculating factorials, generating Fibonacci series, reversing a number, checking for palindromes, and demonstrating class and object in OOP. Each program is accompanied by its respective code and a brief explanation of its purpose.

Uploaded by

desix88776
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 simple Java programs​​, written in a​​beginner-friendly / lab-record style​​, with a clear​​Aim​

1
​for each.​

​1. Hello World Program​


​Aim​

​To write a Java program to print “Hello World”.​

​class HelloWorld {​
​public static void main(String[] args) {​
​[Link]("Hello World");​
​}​
​}​

​2. Addition of Two Numbers​


​Aim​

​To write a Java program to add two numbers.​

​import [Link];​

​class AddNumbers {​
​public static void main(String[] args) {​
​int a, b, sum;​
​Scanner sc = new Scanner([Link]);​

​ = [Link]();​
a
​b = [Link]();​
​sum = a + b;​

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


​}​
​}​
​3. Largest of Two Numbers​
​Aim​

​To write a Java program to find the largest of two numbers.​

​import [Link];​

​class LargestTwo {​
​public static void main(String[] args) {​
​int a, b;​
​Scanner sc = new Scanner([Link]);​

​ = [Link]();​
a
​b = [Link]();​

​if (a > b)​


​[Link](a + " is largest");​
​else​
​[Link](b + " is largest");​
​}​
​}​

​4. Even or Odd Number​


​Aim​

​To write a Java program to check whether a number is even or odd.​

​import [Link];​

​class EvenOdd {​
​public static void main(String[] args) {​
​int n;​
​Scanner sc = new Scanner([Link]);​

​n = [Link]();​

​if (n % 2 == 0)​
​[Link]("Even number");​
​else​
​[Link]("Odd number");​
​}​
​}​

​5. Factorial of a Number​


​Aim​

​To write a Java program to find the factorial of a number.​

​import [Link];​

​class Factorial {​
​public static void main(String[] args) {​
​int n;​
​long fact = 1;​
​Scanner sc = new Scanner([Link]);​

​n = [Link]();​

​for (int i = 1; i <= n; i++)​


​fact *= i;​

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


​}​
​}​

​6. Fibonacci Series​


​Aim​

​To write a Java program to generate Fibonacci series.​

​import [Link];​

​class Fibonacci {​
​public static void main(String[] args) {​
​int n, a = 0, b = 1, c;​
​Scanner sc = new Scanner([Link]);​
​ = [Link]();​
n
​[Link](a + " " + b + " ");​

​for (int i = 3; i <= n; i++) {​


​c = a + b;​
​[Link](c + " ");​
​a = b;​
​b = c;​
​}​
​}​
​}​

​7. Reverse a Number​


​Aim​

​To write a Java program to reverse a given number.​

​import [Link];​

​class ReverseNumber {​
​public static void main(String[] args) {​
​int n, rev = 0;​
​Scanner sc = new Scanner([Link]);​

​n = [Link]();​

​while (n != 0) {​
​rev = rev * 10 + n % 10;​
​n /= 10;​
​}​

​[Link]("Reversed number = " + rev);​


​}​
​}​

​8. Palindrome Number​


​Aim​

​To write a Java program to check whether a number is palindrome.​

​import [Link];​

​class Palindrome {​
​public static void main(String[] args) {​
​int n, temp, rev = 0;​
​Scanner sc = new Scanner([Link]);​

​ = [Link]();​
n
​temp = n;​

​while (n != 0) {​
​rev = rev * 10 + n % 10;​
​n /= 10;​
​}​

​if (temp == rev)​


​[Link]("Palindrome");​
​else​
​[Link]("Not Palindrome");​
​}​
​}​

​9. Largest of Three Numbers​


​Aim​

​To write a Java program to find the largest of three numbers.​

​import [Link];​

​class LargestThree {​
​public static void main(String[] args) {​
​int a, b, c;​
​Scanner sc = new Scanner([Link]);​

​ = [Link]();​
a
​b = [Link]();​
​c = [Link]();​
​if (a > b && a > c)​
​[Link](a + " is largest");​
​else if (b > c)​
​[Link](b + " is largest");​
​else​
​[Link](c + " is largest");​
​}​
​}​

​10. Simple OOP Program (Class and Object)​


​Aim​

​To write a Java program to demonstrate class and object.​

​class Student {​
​int roll;​

​void display() {​
​[Link]("Roll Number: " + roll);​
​}​

​public static void main(String[] args) {​


​Student s = new Student();​
​[Link] = 101;​
​[Link]();​
​}​
​}​

You might also like