Professional Documents
Culture Documents
Narendranath Reddy
Java Assignment - 1
QUESTION:
1. A milk carton can hold 3.78 liters of milk. Each morning, a dairy farm ships
cartons of milk to a local grocery store. The cost of producing one liter of milk
is Rs. 50, and the profit of each carton of milk is Rs. 7. Write a java program
that does the following:
a. Prompts the user to enter the total amount of milk produced in the morning.
b. Outputs the number of milk cartons needed to hold milk.
c. Outputs the cost of producing milk.
d. Outputs the profit for producing milk.
Code : MAM YOU CAN COPY THIS CODE ,IT IS NOT A SCREENSHOT
import java.util.Scanner;
public class beginner {
public static void main(String[] args) {
//a. Prompts the user to enter the total amount of milk produced in
the morning.
System.out.println("enter the total amount of milk produced : ");
Scanner sc = new Scanner(System.in);
double milk_p = sc.nextDouble();
//b. Outputs the number of milk cartons needed to hold milk.
double milk_cartons = (int)(milk_p / 3.78);
System.out.print("No of cartons = ");
System.out.println(milk_cartons);
//c. Outputs the cost of producing milk.
double cost = milk_p * 50;
System.out.print("Cost of producing milk = ");
System.out.println(cost);
//d. Outputs the profit for producing milk.
double profit = milk_cartons * 7;
System.out.print("Profit = ");
System.out.println(profit);
}
}
OUTPUT :
(21BCE7761) K.Narendranath Reddy
Java Assignment - 1
2.
Code:
import java.util.Scanner;
import java.util.prefs.BackingStoreException;
public class beginner{
public static void main(String[] args) {
Scanner sin=new Scanner(System.in);
System.out.print("enter basic salary :");
int basic=sin.nextInt();
int gross;
int da;
int home;
int instaneous;
int travel;
int one_day;
if(basic>15000){
da=(basic*10/100);
travel=(basic*5/100);
home=(basic*7/100);;
instaneous=1500;
gross=da+travel+home+instaneous+basic;
System.out.print("gross salary :");
System.out.println(gross);}
else if(basic>10000 && basic<=15000){
da=(basic*7/100);
travel=(basic*3/100);
home=(basic*4/100);
one_day=(basic+da)/30;
instaneous=30*one_day;
gross=da+travel+home+instaneous+basic;
System.out.print("gross salary :");
System.out.print(gross);}
else if(basic<=10000){
travel=(basic*3/100);
one_day=basic/30;
instaneous=20*one_day;
gross=travel+instaneous+basic;
System.out.print("gross salary :");
System.out.println(gross);}
}
}
OUTPUT:
(21BCE7761) K.Narendranath Reddy
Java Assignment - 1
3. Write a java program to find the sum of the Exponential series given below
using recursion. Take x and n value from the user. 1+𝑥1!+𝑥22!+𝑥33!+⋯+𝑥𝑛𝑛!
CODE:
import java.util.Scanner;
}
}
OUTPUT:
(21BCE7761) K.Narendranath Reddy
Java Assignment - 1
5. Write a java program to print and count the number of Krishnamurthy in a
range between a and b where a=100,b=400 using function int krisno(n,a,b). A
Krishnamurthy number is a number whose sum of the factorial of digits is equal to
the number itself.
CODE:
import java.net.SocketTimeoutException;
import java.sql.SQLOutput;
import java.util.Scanner;
public class beginner {
public static void main(String[] args) {
}
if(sum ==i)
c = c+1;
}
return c;
}
public static int fact(int m){
int fac = 1;
if(m==1 && m==0)
return 1;
else{
for(int i=1;i<=m;i++)
fac = fac*i;
return fac;
}
}
}
(21BCE7761) K.Narendranath Reddy
Java Assignment - 1
output: