[Go to site: main page, start]

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

Java Basics Programs

The document contains a series of Java programming examples for BCA I Year II Semester students at JMS Group of Institution, Hapur. Each program demonstrates basic programming concepts such as addition, even/odd checking, finding the largest number, swapping numbers, calculating simple interest, factorial, prime number checking, reversing a number, summing digits, and calculating student percentage. These examples serve as practical exercises to enhance students' understanding of Java programming.

Uploaded by

kashishgurjar42
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)
5 views5 pages

Java Basics Programs

The document contains a series of Java programming examples for BCA I Year II Semester students at JMS Group of Institution, Hapur. Each program demonstrates basic programming concepts such as addition, even/odd checking, finding the largest number, swapping numbers, calculating simple interest, factorial, prime number checking, reversing a number, summing digits, and calculating student percentage. These examples serve as practical exercises to enhance students' understanding of Java programming.

Uploaded by

kashishgurjar42
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

JMS GROUP OF INSTITUTION, HAPUR

BCA I YEAR II SEM


Java Basic Program Examples
Program 1. Addition of Two Numbers
import [Link];
class AddTwoNumbers
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
int a, b, sum;
[Link]("Enter first number: ");
a = [Link]();
[Link]("Enter second number: ");
b = [Link]();
sum = a + b;
[Link]("Sum = " + sum);
}
}

Program 2. Even or Odd Number


import [Link];
class EvenOdd
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
int num;
[Link]("Enter a number: ");
num = [Link]();
if(num % 2 == 0)
[Link]("Even Number");
else
[Link]("Odd Number");
}
}
Program 3. Largest of Two Numbers
import [Link];
class LargestTwo
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
int a, b;
[Link]("Enter first number: ");
a = [Link]();
[Link]("Enter second number: ");
b = [Link]();
if(a > b)
[Link]("Largest = " + a);
else
[Link]("Largest = " + b);
}
}
Program 4. Swap Two Numbers
import [Link];
class SwapNumbers
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
int a, b, temp;

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


a = [Link]();

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


b = [Link]();

temp = a;
a = b;
b = temp;

[Link]("After swapping:");
[Link]("a = " + a);
[Link]("b = " + b);
}
}
Program 5. Simple Interest
import [Link];
class SimpleInterest
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
float p, r, t, si;

[Link]("Enter Principal: ");


p = [Link]();

[Link]("Enter Rate: ");


r = [Link]();

[Link]("Enter Time: ");


t = [Link]();

si = (p * r * t) / 100;
[Link]("Simple Interest = " + si);
}
}

Program 6. Factorial of a Number


import [Link];
class Factorial
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
int num, i, fact = 1;

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


num = [Link]();

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


{
fact = fact * i;
}

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


}
}
Program 7. Prime Number Check
import [Link];
class PrimeNumber
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
int num, i, count = 0;

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


num = [Link]();

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


{
if(num % i == 0)
count++;
}

if(count == 2)
[Link]("Prime Number");
else
[Link]("Not a Prime Number");
}
}

Program 8. Reverse a Number


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

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


num = [Link]();

while(num != 0)
{
rev = rev * 10 + num % 10;
num = num / 10;
}
[Link]("Reverse = " + rev);
}
}
Program 9. Sum of Digits
import [Link];
class SumOfDigits
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
int num, sum = 0;
[Link]("Enter a number: ");
num = [Link]();

while(num != 0)
{
sum = sum + num % 10;
num = num / 10;
}

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


}
}

Program 10. Calculate Student Percentage


import [Link];
class Percentage
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
int m1, m2, m3, m4, m5;
int total;
float per;

[Link]("Enter marks of 5 subjects: ");


m1 = [Link]();
m2 = [Link]();
m3 = [Link]();
m4 = [Link]();
m5 = [Link]();

total = m1 + m2 + m3 + m4 + m5;
per = total / 5.0f;

[Link]("Total = " + total);


[Link]("Percentage = " + per);
}}

You might also like