Project
Project
// To print s
import [Link].*;
class P1
{
public static void main (String args[])
{
Scanner sc=new Scanner ([Link]);
[Link] ("*****");
[Link] ("* ");
[Link] ("*****");
[Link] (" *");
[Link] ("*****");
}
}
Output:
Program-2
// To display the given format
import [Link].*;
class P2
{
public static void main (String agrs[])
{
[Link]("******");
[Link]("* *");
[Link]("* *");
[Link]("* *");
[Link]("******");
}
}
Output:
Program-3
Output:
Program-4
// A sample program to illustrate relational operator
import [Link].*;
class P4
{
public static void main (String agrs [])
{
int a=22,b=5;
[Link]("Answer when a<b:"+(a<b));
[Link]("Answer when a>b:"+(a>b));
[Link]("Answer when a<=b:"+(a<=b));
[Link]("Answer when a>=b:"+(a>=b));
[Link]("Answer when a==b:"+(a==b));
[Link]("Answer when a!=b:"+(a!=b));
}
Output :
Program – 5
//A program to find area, perimeter and diagonal of a square
class P5
{
public static void main(String args[])
{
int s, ar=0,p=0;
double d=0.0;
s=25;
ar=s*s;
p=4*s;
d=[Link](2)*s;
[Link]("The Area of square="+ar);
[Link]("The perimeter of square="+p);
[Link]("The diagonal of square="+d);
}
}
Output:
Program-6
// A program to display result
import [Link].*;
class P6
{
public static void main (String args[])
{
Scanner in = new Scanner([Link]);
int a,b,res;
[Link]("Enter tens digit:");
a=[Link]();
[Link]("Enter unit digits:");
b=[Link]();
res=((10*a+b)+(10*b+a))/(a-b);
[Link]("The answer:"+res);
}
Output:
Program-7
}
}
Output:
Program-8
import [Link].*;
class P8
{
public static void main (String args[])
{
Scanner sc=new Scanner ([Link]);
double sp,p,cp,dy;
[Link]("Enter the total selling price");
sp=[Link]();
[Link]("Enter the total profit:");
p=[Link]()
cp=sp-p;
dy=cp/15;
[Link]("cost price of one item:"+dy);
}
}
Output:
Program-9
// A program to calculate gross salary and net salary
import [Link].*;
class P9
{
public static void main(String args[])
{
Scanner in=new Scanner([Link]);
int basic;
double da,hra,pf,gp=0,np=0;
String name;
[Link]("Enter the name of the employee");
name=[Link](); [Link]("Enter basic salary");
basic=[Link]();
da=basic*30.0/100.0;
hra=basic*12.5/100.0;
pf=basic*10.0/100.0;
gp=basic+da+hra;
np=gp-pf;
[Link]("Empolyee's Name:"+name);
[Link]("Gross pay:Rs."+gp); [Link]("Net
pay:Rs."+np);
}
}
Output:
Program-10
Output:
Program-11
// to input the temperature in farenheit and convert it into celisus
import [Link].*;
class temp
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
double F,C;
[Link]("Enter the temperature in farenheit");
F=[Link]();
C=(F-32)*5/9.0;
[Link]("Enter the value of celisus");
}
}
Output:
Program-12
//To use a formula
import [Link].*;
class Mathematics
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
[Link]("Enter the value of x1");
int x1=[Link]();
[Link]("Enter the value of x2");
int x2=[Link]();
[Link]("Enter the value y1");
int y1=[Link]();
[Link]("Enter the value of y2");
int y2=[Link]();
double d;
d=[Link]([Link]((x2-x1),2));
[Link]((y2-y1),2);
}
}
Output:
Program-13
//To display my answer
class P13
{
public static void main(String args[])
{
double m=[Link](8.0); [Link]("Result of rint
value="+m);
double n=[Link](8.49);
[Link]("Result of rint value="+n);
double k=[Link](8.50);
[Link]("Result of rint value="+k);
double c=[Link](8.51);
[Link]("Result of rint value="+c);
double t=[Link](-8.0);
[Link]("Result of rint value="+t);
double d=[Link](-8.49);
[Link]("Result of rint value="+d);
double s=[Link](-8.50); [Link]("Result of rint
value="+s);
double a=[Link](-8.51);
[Link]("Result of rint value="+a);
}
}
Output:
Program-14
//WAP to display the following
import [Link].*;
class P16
{
public static void main(String agrs[])
{
[Link]("**********************************");
[Link]("\t\t\t ");
[Link]("\t\tABC Restaurant");
[Link]("Date:14 April 2024\\tbill no:2403");
[Link]("SNO. \tItem\t\tRate\t\tQty\tTotal");
[Link]("1.\tBiriyani\t200\t\t1\t200");
[Link]("2.\tFried rice\t180\t\t2\t360");
[Link]("3.\tPopcorn chicken\t150\t\t2\t300");
[Link]("4.\tMojito\t\t80\t\t2\t160");
[Link]("\t\t\t\t\tTotal 1020");
[Link]("____________________________________");
[Link]("Thank you! Visit again!");
[Link]("***********************************");
}
}
Output:
Program-15
// To print chittu for five times
import [Link].*;
class chittu
{
public static void main (String args[])
{
for(int i=1;i<=5;i=i+1)
[Link]("chittu");
Output:
Program-16
//To arrange in ascending order
import [Link].*;
public class AscendingOrder {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
Output:
Program-18
//sample program
Import [Link].*;
class sample
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
double sp,p,cp,dy; [Link]("Enter the total selling
price");
sp=[Link]();
[Link]("Enter the total profit");
p=[Link]();
cp=sp-p;
dy=cp/15;
[Link]("Cost price of one item:"+dy);
}
Output:
Program-19
// To display the numbers
public class Print1010 {
public static void main(String[] args) {
for (int i = 0; i < 5; i++) {
[Link]("1010");
}
}
}
Output:
Program-20
import [Link];
class choice
{
public class IceCreamOrChocolate {
public static void main(String[] args) {
// Create a Scanner object to read input
Scanner scanner = new Scanner([Link]);
Output:
Program-21
//To find the cosine of an angle
public class Cosine_value
{
public static void main(String args[])
{
double deg=45;
double radians=[Link](deg);
double cosine=[Link](radians);
[Link]("Value of Cos 45 degree="+(float)cosine);
}
}
Output:
Program-22
// a program to find the value of an expression
import [Link].*;
public class expression
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
int a,b,c;
double d;
[Link]("Enter values of a,b and c");
a=[Link]();
b=[Link]();
c=[Link]();
d=1/[Link](a,2)+1/[Link](b,3)+1/[Link](c,4);
[Link]("Value of the expression="+d);
}
}
Output:
Program -23
// a program to dispaly the pattern
public class Pattern
{
public static void main(String args[])
{
int a,b;
[Link]("The Pattern:");
for(a=1;a<=a;b++)
{
for(b=1;b<=a;b++)
[Link](b+"");
[Link]();
}
}
}
Output:
Program-24
// A program to display the pattern
public class JP
{
public static void main(String args[])
{
int i,j;
[Link]("The Pattern:");
for (i=5;i>=1;i--)
{
for(j=i;j>=1;j--)
[Link](j+" ");
[Link]();
}
}
}
Output:
Program – 25
//to display the pattern
public class example
{
public static void main(String args[])
{
int i,j;
[Link]("The Pattern:");
for(i=5;i>=1;i--)
{
for(j=i;j>=1;j--)
[Link](j+"");
[Link]();
}
}
}
Output:
Program-26
// program to display value of cosine for aa angle
public class rad
{
public static void main(String args[])
{
int a=60;
double rad=(22.0/(7.0*180))*a;
double d=[Link](rad);
[Link]("Value of Cos 60 degree is"+(float)d);
}
}
Output:
Program-27
// a program using do-while
import [Link].*;
class Digits
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
int d,n;
[Link]("Enter a number");
n=[Link]();
//Displaying even/odd digits starting from unit place
do
{
d=n%10;
if(d%2==0)
[Link](d+":an even digit");
else
[Link](d+":an odd digit");
n=n/10;
}
while(n>0);
}
}
Output:
Program-28
//A program to display whether the number is positive of negative
import [Link].*;
class Number
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
int n;
do
{
[Link]("Enter a number and zero to terminate:");
n=[Link]();
if(n==0)
break;
if(n>0)
[Link](n+":a positive number");
else
[Link](n+":a negative number");
}
while(true);
[Link]("Program terminates!");
}
}
Output:
Program-29
import [Link];
// Constructor
public Patient(String name, int age, String disease, String
contactNumber) {
[Link] = name;
[Link] = age;
[Link] = disease;
[Link] = contactNumber;
}
if (isEligibleForDiscount()) {
[Link]("Eligible for 50% Medical Insurance
Discount\n");
} else {
[Link]("Not eligible for 50% Medical Insurance
Discount\n");
}
}
Output:
Program-30
public class DisplayAlphabets
{
public static void main(String[] args)
{
// Displaying uppercase alphabets from A to Z
[Link]("Uppercase Alphabets:");
for (char letter = 'A'; letter <= 'Z'; letter++)
{
[Link](letter + " ");
}
Output:
Program-31
public class p31
{
public static void main(String[] args)
{
// Loop to display the number 23456 four times
for (int i = 0; i < 4; i++) {
[Link](23456);
}
}
}
Output:
Program-32
import [Link].*;
Output:
Program-33
import [Link];
Program -34
import [Link];
import [Link];
Output:
Program – 35
import [Link];
// Closing statement
[Link]("\nThe complaint has been successfully filed.
The police will take immediate action.");
Output:
Program-36
//To print a Robot Face
public class RobotFace {
public static void main(String[] args) {
// Display the robot face using asterisks
[Link](" ***** ");
[Link](" * * ");
[Link](" * O O * ");
[Link](" * ^ * ");
[Link](" * '-' * ");
[Link](" * * ");
[Link](" ***** ");
}
}
Output:
Program-37
import [Link];
case 2:
[Link]("Yellow signal: Prepare to stop.");
break;
case 3:
[Link]("Green signal: You can go now.");
break;
default:
[Link]("Invalid choice. Please select a valid
option (1, 2, or 3).");
break;
}
Output:
Program-38
import [Link];
Output:
Program-40
// to choose a fruit
import [Link];
Output:
Program-41
//To choose vote
import [Link];
public class VotingSystem
{
Output:
Program-42
// a program on accounts of a chat shop
import [Link];
while (true) {
// Display menu
[Link]("\nWelcome to Pani Puri Shop!");
[Link]("Menu:");
[Link]("1. Pani Puri - Rs. 50");
[Link]("2. Bhel - Rs. 30");
[Link]("3. Pav Bhaji - Rs. 80");
[Link]("4. View Total Sales");
[Link]("5. Exit");
[Link]("Please enter your choice (1-5): ");
switch (choice) {
case 1:
// Selling Pani Puri
[Link]("Enter the number of Pani Puri plates
sold: ");
int paniPuriCount = [Link]();
paniPuriSold += paniPuriCount;
totalAmount += paniPuriCount * PANI_PURI_PRICE;
[Link]("Sold " + paniPuriCount + " plates of
Pani Puri.");
break;
case 2:
// Selling Bhel
[Link]("Enter the number of Bhel plates sold:
");
int bhelCount = [Link]();
bhelSold += bhelCount;
totalAmount += bhelCount * BHEL_PRICE;
[Link]("Sold " + bhelCount + " plates of
Bhel.");
break;
case 3:
// Selling Pav Bhaji
[Link]("Enter the number of Pav Bhaji plates
sold: ");
int pavBhajiCount = [Link]();
pavBhajiSold += pavBhajiCount;
totalAmount += pavBhajiCount * PAV_BHAJI_PRICE;
[Link]("Sold " + pavBhajiCount + " plates of
Pav Bhaji.");
break;
case 4:
// Display total sales
[Link]("\nTotal Sales:");
[Link]("Pani Puri Sold: " + paniPuriSold + "
plates");
[Link]("Bhel Sold: " + bhelSold + " plates");
[Link]("Pav Bhaji Sold: " + pavBhajiSold + "
plates");
[Link]("Total Amount Collected: Rs. " +
totalAmount);
break;
case 5:
// Exit the program
[Link]("Exiting the system. Thank you!");
[Link]();
return;
default:
[Link]("Invalid choice! Please choose a valid
option.");
}
}
}
}
Output:
Program-43
// to calculate the income tax
import [Link];
Program-44
// to calculate monthly expenditure
import [Link];
public class MonthlyExpenditureCalculator {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
Output:
Program-45
import [Link];
if ([Link]("yes") &&
[Link]("yes")) {
[Link]("- A degree in Healthcare or Nursing could
be a great fit for you!");
} else if ([Link]("yes") &&
[Link]("yes")) {
[Link]("- A degree in Computer Science or
Engineering could be a great fit for you!");
} else if ([Link]("yes") &&
[Link]("yes")) {
[Link]("- A degree in Psychology or Education
could be a good choice for you!");
} else if ([Link]("yes") &&
[Link]("yes")) {
[Link]("- A degree in Graphic Design, Digital
Media, or Web Development could be a great choice for you!");
} else {
[Link]("- Based on your answers, you might want
to consider exploring other options.");
}
Output:
Program-46
public class TriangleAreaCalculator {
public static void main(String[] args) {
// Given sides of the right triangle
double side1 = 4.0; // base (in cm)
double side2 = 4.0; // height (in cm)
Output:
Program-47
import [Link];
Output:
Program-48
import [Link];
Output:
Program-49
// to input the details of a student
import [Link];
Output:
Program-50
//to display hand
public class HandWithAsterisks {
public static void main(String[] args) {
// Print the hand using asterisks
[Link](" * * ");
[Link](" * * ");
[Link](" * * ");
[Link](" * * * * * ");
[Link](" * * * * * ");
[Link](" * * ");
[Link](" * * ");
[Link](" * * ");
[Link](" * * ");
}
}
Output: