0% found this document useful (0 votes)
51 views8 pages

Name:-Roll No: - Class:-: Badugula Rohan Reddy 20009 CSEA / Group-A

This document contains a lab assignment submitted by Badugula Rohan Reddy with roll number 20009 from class CSEA/Group-A. The assignment contains 7 coding problems involving calculating quantities like total weight, distance between points, acceleration, perimeter of a circle, sum of digits in a number, converting time units to seconds, and calculating tax and tip on a meal. For each problem, the code to solve it and the output is provided.

Uploaded by

rohan reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views8 pages

Name:-Roll No: - Class:-: Badugula Rohan Reddy 20009 CSEA / Group-A

This document contains a lab assignment submitted by Badugula Rohan Reddy with roll number 20009 from class CSEA/Group-A. The assignment contains 7 coding problems involving calculating quantities like total weight, distance between points, acceleration, perimeter of a circle, sum of digits in a number, converting time units to seconds, and calculating tax and tip on a meal. For each problem, the code to solve it and the output is provided.

Uploaded by

rohan reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

LAB – 1

NAME :- Badugula Rohan Reddy


Roll no :- 20009
Class :- CSEA / Group-A
1) Widgets and gizmo.

Code:-
package com.company;
import java.util.Scanner;
public class Ass_1_1 {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
double widgets,gizmo;
double total;
System.out.println("Enter the number of widgets : ");
widgets = sc.nextDouble();
System.out.println("Enter the number of gizmo : ");
gizmo = sc.nextDouble();
total = (75*widgets+112*gizmo)/1000;
System.out.println( total + " Kilograms!");

}
}

Output :-

2)Distance between 2 points.


Code:-
package com.company;
import java.util.Scanner;
import java.lang.Math;
public class Ass_1_2 {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
double x1,y1,x2,y2,distance;
System.out.println("Enter the first point");
x1 = sc.nextDouble();
y1 = sc.nextDouble();
System.out.println("Enter the second point");
x2 = sc.nextDouble();
y2 = sc.nextDouble();
distance = Math.sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
System.out.format("The distance is %.2f",distance);
}
}

Output :-

3)Physics : Acceleration.
Code:-
package com.company;
import java.util.Scanner;
public class Ass_1_3 {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
double v0,v1,t,a;
v0 = sc.nextDouble();
v1 = sc.nextDouble();
t = sc.nextDouble();
a = ((v1 - v0)/t);
System.out.format("%.2f",a);
}
}

Output:-

4) Perimeter of Circle.

Code:-
package com.company;
import java.util.Scanner;
public class Ass_1_4 {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
double radius,perimeter;
System.out.println("Enter the radius:");
radius = sc.nextInt();
perimeter = 2 * 3.14 * radius;
System.out.println("The perimeter is : "+
perimeter);
}
}

Output:-

5) Sum of all digits.

Code:-
package com.company;
import java.util.Scanner;
public class Ass_1_5 {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int num,sum = 0,i = 0;
System.out.println("Enter the number");
num = sc.nextInt();
while(num != 0)
{
i = num % 10;
sum = sum + i;
num = num / 10;
}
System.out.println("The sum of digits is :
"+sum);
}
}

Output:-

6) Units of Time.

Code:-
package com.company;
import java.util.Scanner;
public class Ass_1_6 {
public static void main(String[] args){
Scanner sc= new Scanner(System.in);
int days,hours,minutes,seconds,total;
days = sc.nextInt();
hours = sc.nextInt();
minutes = sc.nextInt();
seconds = sc.nextInt();
total =
days*86400+hours*3600+minutes*60+seconds;
System.out.format("The total Seconds for %d
days %d hours %d minutes and %d seconds is %d
seconds",days,hours,minutes,seconds,total);

}
}

Output:-

7) Tax and Tip.

Code:-
package com.company;
import java.util.Scanner;
public class Ass_1_7 {
public static void main(String[] args){
Scanner sc =new Scanner(System.in);
double meal,tax,mealTax,tips,total;
meal = sc.nextDouble();
tax = meal*5 /100;
mealTax = meal + tax;
tips = meal*18 /100;
total = mealTax + tips;
System.out.printf("meal = %.2f \n",meal);
System.out.printf("tax = %.2f \n",tax);
System.out.printf("meal tax = %.2f\n",mealTax);
System.out.printf("tips = %.2f \n",tips);
System.out.printf("total cost = %.2f \n",total);

}
}

Output:-

You might also like