Program 1:
Write a java program to convert the given number of eggs to number of gross, no of dozens
and extras:
144 eggs=1 gross 12 eggs=1 dozen
Example:
no of eggs=1342
9 Gross 3 dozen 10 extras
Source Code:
import [Link];
public class A
{
static public void main(String args[])
{
int n;
int count=0;
int c=0;
Scanner sc=new Scanner([Link]);
n=[Link]();
while(n>144)
{
n=n-144;
if(n>=0)
{
count++;
}
}
while(n>12)
{
n=n-12;
if(n>=0)
{
c++;
}
}
[Link]("Gross:" +count);
[Link]("Dozen:" +c);
[Link]("Extras:" +n);
}
}
Output:
Program 2:
write a java program to calculate simple interest and compound interest.
Source Code:
import [Link] .*;
class Interest
public static void main (String args[])
{
double p,r,t,simple,compound;
int n;
Scanner sc=new Scanner(System. in);
[Link]("Enter the amount:");
p=[Link]();
[Link]("Enter Number of years:");
t=[Link]();
System. out. println("Enter the Rate of interest");
r=[Link]();
[Link]("Enter Number of times:");
n=[Link]();
simple=(p*t*r)/100;
compound=p*[Link](1.0+(r/n),n*t)-p;
[Link]("Simple Interest="+simple);
[Link]. println("Compound Interest="+compound);
Output:
Program 3:
write a java program to convert seconds into hh:mm:ss format
Seconds H:M:S
5400 1:30:00
Source Code:
import [Link] .*;
class Time
public static void main (String args[])
int n;
Scanner sc=new Scanner(System. in);
[Link]("Enter the second:");
n=[Link]();
int seconds = n % 3600 % 60;
int minutes = (int) [Link](n % 3600 / 60);
int hours = (int) [Link](n / 3600);
String HH = ((hours < 10) ? "0" : "") + hours;
String MM = ((minutes < 10) ? "0" : "") + minutes;
String SS = ((seconds < 10) ? "0" : "") + seconds;
[Link](HH + ":" + MM + ":" + SS);
}
Output:
Program 4:
Write a java program to convert money into denominations. For 16108 :
8 * 2000 = 16000
1 * 100 = 100
1*5=5
1*2=2
1*1=1
Source Code:
Output:
Program 5:
Write a Java Program to Generate a random number between 25 to 50( both included)
Hint: use [Link]();
Source Code:
import [Link] .Scanner;
import [Link].*;
class Random
public static void main (String args[])
int upper;
int lower;
Scanner sc=new Scanner(System. in);
[Link]("Enter the upper value:");
upper=[Link]();
[Link]("Enter the lower value:");
lower=[Link]();
int r = (int) ([Link]() * (upper - lower)) + lower;
[Link](r);
Output:
Program 6:
Date Program :