You are on page 1of 7

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 java.util.Scanner;
public class A
{
static public void main(String args[])
{
int n;
int count=0;
int c=0;
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
while(n>144)
{
n=n-144;
if(n>=0)
{
count++;
}
}
while(n>12)
{
n=n-12;
if(n>=0)
{
c++;
}
}
System.out.println("Gross:" +count);
System.out.println("Dozen:" +c);
System.out.println("Extras:" +n);
}
}

Output:

Program 2:

write a java program to calculate simple interest and compound interest.

Source Code:

import java.util .*;

class Interest

public static void main (String args[])

{
double p,r,t,simple,compound;

int n;

Scanner sc=new Scanner(System. in);

System.out.println("Enter the amount:");

p=sc.nextDouble();

System.out.println("Enter Number of years:");

t=sc.nextDouble();

System. out. println("Enter the Rate of interest");

r=sc.nextDouble();

System.out.println("Enter Number of times:");

n=sc.nextInt();

simple=(p*t*r)/100;

compound=p*Math.pow(1.0+(r/n),n*t)-p;

System.out.println("Simple Interest="+simple);

System.out. 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 java.util .*;

class Time

public static void main (String args[])

int n;

Scanner sc=new Scanner(System. in);

System.out.println("Enter the second:");

n=sc.nextInt();

int seconds = n % 3600 % 60;

int minutes = (int) Math.floor(n % 3600 / 60);

int hours = (int) Math.floor(n / 3600);

String HH = ((hours < 10) ? "0" : "") + hours;

String MM = ((minutes < 10) ? "0" : "") + minutes;

String SS = ((seconds < 10) ? "0" : "") + seconds;

System.out.println(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 Math.random();

Source Code:

import java.util .Scanner;

import java.lang.Math.*;
class Random

public static void main (String args[])

int upper;

int lower;

Scanner sc=new Scanner(System. in);

System.out.println("Enter the upper value:");

upper=sc.nextInt();

System.out.println("Enter the lower value:");

lower=sc.nextInt();

int r = (int) (Math.random() * (upper - lower)) + lower;

System.out.println(r);

Output:

Program 6:
Date Program :

You might also like