Simple Java Programs
Program 1: Hello World
Objective: Learn the implementation of the selected Java program.
Description: This document contains a collection of introductory Java programming examples.
Each example demonstrates a basic programming concept such as variables, operators,
conditional statements, loops, input handling using Scanner, and simple problem solving. Readers
are encouraged to compile, execute, modify, and experiment with every program. Understanding
these examples provides a strong foundation for learning object-oriented programming. This
document contains a collection of introductory Java programming examples. Each example
demonstrates a basic programming concept such as variables, operators, conditional statements,
loops, input handling using Scanner, and simple problem solving. Readers are encouraged to
compile, execute, modify, and experiment with every program. Understanding these examples
provides a strong foundation for learning object-oriented programming.
Program
public class HelloWorld {
public static void main(String[] args) {
[Link]("Hello World");
}
}
Result: The program was compiled and executed successfully with the expected output.
Simple Java Programs
Program 2: Addition of Two Numbers
Objective: Learn the implementation of the selected Java program.
Description: This document contains a collection of introductory Java programming examples.
Each example demonstrates a basic programming concept such as variables, operators,
conditional statements, loops, input handling using Scanner, and simple problem solving. Readers
are encouraged to compile, execute, modify, and experiment with every program. Understanding
these examples provides a strong foundation for learning object-oriented programming. This
document contains a collection of introductory Java programming examples. Each example
demonstrates a basic programming concept such as variables, operators, conditional statements,
loops, input handling using Scanner, and simple problem solving. Readers are encouraged to
compile, execute, modify, and experiment with every program. Understanding these examples
provides a strong foundation for learning object-oriented programming.
Program
import [Link];
class Add {
public static void main(String[] args){
Scanner s=new Scanner([Link]);
int a=[Link]();
int b=[Link]();
[Link]("Sum = "+(a+b));
}
}
Result: The program was compiled and executed successfully with the expected output.
Simple Java Programs
Program 3: Largest of Three Numbers
Objective: Learn the implementation of the selected Java program.
Description: This document contains a collection of introductory Java programming examples.
Each example demonstrates a basic programming concept such as variables, operators,
conditional statements, loops, input handling using Scanner, and simple problem solving. Readers
are encouraged to compile, execute, modify, and experiment with every program. Understanding
these examples provides a strong foundation for learning object-oriented programming. This
document contains a collection of introductory Java programming examples. Each example
demonstrates a basic programming concept such as variables, operators, conditional statements,
loops, input handling using Scanner, and simple problem solving. Readers are encouraged to
compile, execute, modify, and experiment with every program. Understanding these examples
provides a strong foundation for learning object-oriented programming.
Program
import [Link];
class Largest{
public static void main(String[] args){
Scanner s=new Scanner([Link]);
int a=[Link](), b=[Link](), c=[Link]();
if(a>b && a>c) [Link](a);
else if(b>c) [Link](b);
else [Link](c);
}
}
Result: The program was compiled and executed successfully with the expected output.
Simple Java Programs
Program 4: Factorial
Objective: Learn the implementation of the selected Java program.
Description: This document contains a collection of introductory Java programming examples.
Each example demonstrates a basic programming concept such as variables, operators,
conditional statements, loops, input handling using Scanner, and simple problem solving. Readers
are encouraged to compile, execute, modify, and experiment with every program. Understanding
these examples provides a strong foundation for learning object-oriented programming. This
document contains a collection of introductory Java programming examples. Each example
demonstrates a basic programming concept such as variables, operators, conditional statements,
loops, input handling using Scanner, and simple problem solving. Readers are encouraged to
compile, execute, modify, and experiment with every program. Understanding these examples
provides a strong foundation for learning object-oriented programming.
Program
import [Link];
class Factorial{
public static void main(String[] args){
Scanner s=new Scanner([Link]);
int n=[Link](), f=1;
for(int i=1;i<=n;i++) f*=i;
[Link](f);
}
}
Result: The program was compiled and executed successfully with the expected output.
Simple Java Programs
Program 5: Palindrome Number
Objective: Learn the implementation of the selected Java program.
Description: This document contains a collection of introductory Java programming examples.
Each example demonstrates a basic programming concept such as variables, operators,
conditional statements, loops, input handling using Scanner, and simple problem solving. Readers
are encouraged to compile, execute, modify, and experiment with every program. Understanding
these examples provides a strong foundation for learning object-oriented programming. This
document contains a collection of introductory Java programming examples. Each example
demonstrates a basic programming concept such as variables, operators, conditional statements,
loops, input handling using Scanner, and simple problem solving. Readers are encouraged to
compile, execute, modify, and experiment with every program. Understanding these examples
provides a strong foundation for learning object-oriented programming.
Program
import [Link];
class Palindrome{
public static void main(String[] args){
Scanner s=new Scanner([Link]);
int n=[Link](), t=n, r=0;
while(n>0){
r=r*10+n%10;
n/=10;
}
[Link](t==r?"Palindrome":"Not Palindrome");
}
}
Result: The program was compiled and executed successfully with the expected output.
Simple Java Programs
Program 6: Prime Number
Objective: Learn the implementation of the selected Java program.
Description: This document contains a collection of introductory Java programming examples.
Each example demonstrates a basic programming concept such as variables, operators,
conditional statements, loops, input handling using Scanner, and simple problem solving. Readers
are encouraged to compile, execute, modify, and experiment with every program. Understanding
these examples provides a strong foundation for learning object-oriented programming. This
document contains a collection of introductory Java programming examples. Each example
demonstrates a basic programming concept such as variables, operators, conditional statements,
loops, input handling using Scanner, and simple problem solving. Readers are encouraged to
compile, execute, modify, and experiment with every program. Understanding these examples
provides a strong foundation for learning object-oriented programming.
Program
import [Link];
class Prime{
public static void main(String[] args){
Scanner s=new Scanner([Link]);
int n=[Link](), count=0;
for(int i=1;i<=n;i++)
if(n%i==0) count++;
[Link](count==2?"Prime":"Not Prime");
}
}
Result: The program was compiled and executed successfully with the expected output.
Simple Java Programs
Program 7: Reverse Number
Objective: Learn the implementation of the selected Java program.
Description: This document contains a collection of introductory Java programming examples.
Each example demonstrates a basic programming concept such as variables, operators,
conditional statements, loops, input handling using Scanner, and simple problem solving. Readers
are encouraged to compile, execute, modify, and experiment with every program. Understanding
these examples provides a strong foundation for learning object-oriented programming. This
document contains a collection of introductory Java programming examples. Each example
demonstrates a basic programming concept such as variables, operators, conditional statements,
loops, input handling using Scanner, and simple problem solving. Readers are encouraged to
compile, execute, modify, and experiment with every program. Understanding these examples
provides a strong foundation for learning object-oriented programming.
Program
import [Link];
class Reverse{
public static void main(String[] args){
Scanner s=new Scanner([Link]);
int n=[Link](), r=0;
while(n>0){
r=r*10+n%10;
n/=10;
}
[Link](r);
}
}
Result: The program was compiled and executed successfully with the expected output.
Simple Java Programs
Program 8: Even or Odd
Objective: Learn the implementation of the selected Java program.
Description: This document contains a collection of introductory Java programming examples.
Each example demonstrates a basic programming concept such as variables, operators,
conditional statements, loops, input handling using Scanner, and simple problem solving. Readers
are encouraged to compile, execute, modify, and experiment with every program. Understanding
these examples provides a strong foundation for learning object-oriented programming. This
document contains a collection of introductory Java programming examples. Each example
demonstrates a basic programming concept such as variables, operators, conditional statements,
loops, input handling using Scanner, and simple problem solving. Readers are encouraged to
compile, execute, modify, and experiment with every program. Understanding these examples
provides a strong foundation for learning object-oriented programming.
Program
import [Link];
class EvenOdd{
public static void main(String[] args){
Scanner s=new Scanner([Link]);
int n=[Link]();
if(n%2==0) [Link]("Even");
else [Link]("Odd");
}
}
Result: The program was compiled and executed successfully with the expected output.
Simple Java Programs
Program 9: Multiplication Table
Objective: Learn the implementation of the selected Java program.
Description: This document contains a collection of introductory Java programming examples.
Each example demonstrates a basic programming concept such as variables, operators,
conditional statements, loops, input handling using Scanner, and simple problem solving. Readers
are encouraged to compile, execute, modify, and experiment with every program. Understanding
these examples provides a strong foundation for learning object-oriented programming. This
document contains a collection of introductory Java programming examples. Each example
demonstrates a basic programming concept such as variables, operators, conditional statements,
loops, input handling using Scanner, and simple problem solving. Readers are encouraged to
compile, execute, modify, and experiment with every program. Understanding these examples
provides a strong foundation for learning object-oriented programming.
Program
import [Link];
class Table{
public static void main(String[] args){
Scanner s=new Scanner([Link]);
int n=[Link]();
for(int i=1;i<=10;i++)
[Link](n+" x "+i+" = "+(n*i));
}
}
Result: The program was compiled and executed successfully with the expected output.
Simple Java Programs
Program 10: Fibonacci Series
Objective: Learn the implementation of the selected Java program.
Description: This document contains a collection of introductory Java programming examples.
Each example demonstrates a basic programming concept such as variables, operators,
conditional statements, loops, input handling using Scanner, and simple problem solving. Readers
are encouraged to compile, execute, modify, and experiment with every program. Understanding
these examples provides a strong foundation for learning object-oriented programming. This
document contains a collection of introductory Java programming examples. Each example
demonstrates a basic programming concept such as variables, operators, conditional statements,
loops, input handling using Scanner, and simple problem solving. Readers are encouraged to
compile, execute, modify, and experiment with every program. Understanding these examples
provides a strong foundation for learning object-oriented programming.
Program
import [Link];
class Fibonacci{
public static void main(String[] args){
Scanner s=new Scanner([Link]);
int n=[Link](),a=0,b=1,c;
for(int i=1;i<=n;i++){
[Link](a+" ");
c=a+b; a=b; b=c;
}
}
}
Result: The program was compiled and executed successfully with the expected output.