0% found this document useful (0 votes)
3 views

Java M2+M3

The document contains a series of Java programming exercises aimed at students, covering topics such as currency conversion, travel time calculation, and basic arithmetic operations. Each exercise includes a problem statement followed by a Java code solution. The document serves as a practical guide for learning Java programming through hands-on coding tasks.

Uploaded by

sssss170520
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Java M2+M3

The document contains a series of Java programming exercises aimed at students, covering topics such as currency conversion, travel time calculation, and basic arithmetic operations. Each exercise includes a problem statement followed by a Java code solution. The document serves as a practical guide for learning Java programming through hands-on coding tasks.

Uploaded by

sssss170520
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

10/28/23, 6:25 PM Java M2+M3

Java M2+M3
[email protected] Switch accounts Draft saved

* Indicates required question

Email *

Record [email protected] as the email to be included with my response

Enter your name? *

Akash P. Shilimkar

Enter batch code ? *

M2

Enter your pass out year and stream *

2023

https://docs.google.com/forms/d/e/1FAIpQLSfTQ6Oqc_OGpKT-Ne14qyrsjr2VAatRlUGtz02mkMwGDNThiQ/viewform?pli=1 1/17
10/28/23, 6:25 PM Java M2+M3

1:->Write a program to read the currency in INR from user and display the currency
in US Dollar?

import java.util.Scanner;
class Currency_converter{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the INR Amount : ");
double INR = sc.nextDouble();

double convert = 0.015;


double USD = (INR >= 0) ? INR * convert : -1;
System.out.println("Amount in USD : " +USD+ "USD");
}
}

2:->Write a program to calculate the time taken for a car to travel 250 kms if the
average speed of the car is 40kmph.

import java.util.Scanner;
class Travel_time{
public static void main(String[] args){
int distance = 250;
int speed = 40;

double time = distance/speed;


System.out.println("Total time taken : "+time);
}
}

https://docs.google.com/forms/d/e/1FAIpQLSfTQ6Oqc_OGpKT-Ne14qyrsjr2VAatRlUGtz02mkMwGDNThiQ/viewform?pli=1 2/17
10/28/23, 6:25 PM Java M2+M3

3:->Let us assume a frog covers 25 cm for 1 hop.the frog wishes to travel frm the
location A to location B the distance between location A and B
is 10 meters. Write a java program to calculate the number of hops required for the
frog to travel from A to B.

class FrogHops{
public static void main(String[] args) {
int disperHop = 25;
int disABMeters = 10;
int disInCm = disABMeters * 100;

int numberOfHops = disInCm / disperHop;

System.out.println("The frog needs " + numberOfHops + " hops to travel from location A
to location B.");
}
}

4:->Rohith opened a new E-Wallet account as there was a scheme for the the first
100 customers will get 100 rs wallet cash as joining bonus and
2rs wallet cash will be added for first 3 transactions. Rohith was 52nd user who
opened the account and he did the following Transactions
T1 : he transfered 25rs to his friend.
T2 : he bought an item worth 20rs
Write a java program to record all the above data and display the final wallet
balance of Rohith Account.

class Ewallet {
public static void main(String[] args) {
int total_Cust = 52;
int joining_Bonus = (total_Cus <= 100) ? 100 : 0;
int trans1 = 25;
int trans2 = 20;
int extraCash = (total_Cust <= 100) ? 2 : 0;
int walletBalance = joining_Bonus + extraCash * ((trans1 > 0 ? 1 : 0) + (trans2 > 0 ? 1 :
0));
System.out.println("Rohith's wallet balance: " + walletBalance + " Rs");
}
}

https://docs.google.com/forms/d/e/1FAIpQLSfTQ6Oqc_OGpKT-Ne14qyrsjr2VAatRlUGtz02mkMwGDNThiQ/viewform?pli=1 3/17
10/28/23, 6:25 PM Java M2+M3

5:->Assume we have 3 products in the cart, the price of the products are 1245,
3200 and 455 rupees respectively. Write a java program
to generate the total cost of all the products. The total cost must include a discount
of 10% and then GST of 18%.

class Product{
public static void main(String[] args){
int p1= 1245;
int p2 = 3200;
int p3 = 455;

int total = p1+p2+p3;


int dis = total - total*10/100;
System.out.println(gst);

int gst = dis + dis*18/100;

System.out.println(gst);

}
}

6:->Store data 10 in a variable x, update the variable with an increase of 15% to the
existing value. use Compound Assignment Operator to update the variable.

class Update_variable{
public static void main(String[] args){
int x =10;
int y = x+x*15/100;

int z = x+=y;

System.out.println(z);

}
}

https://docs.google.com/forms/d/e/1FAIpQLSfTQ6Oqc_OGpKT-Ne14qyrsjr2VAatRlUGtz02mkMwGDNThiQ/viewform?pli=1 4/17
10/28/23, 6:25 PM Java M2+M3

7:->Smith has 2500 rupees in his wallet account, what would be the amount in his
wallet after the following transactions :
T1 : bought a product of worth 250 rupees using the wallet balance
T2 : wallet was added with extra 20 rupees as a payback.
Write a java program to capture the given data, execute the specified transaction
using Compound assignment operator, and obtain the final wallet balance.

class Wallet_transaction {
public static void main(String[] args) {
double walletBal = 2500.0;
double trans1 = 250.0;
double trans2 = 20.0;
walletBal -= trans1;
walletBal += trans2;
System.out.println("The final wallet balance is: " + walletBal + " rupees");
}
}

https://docs.google.com/forms/d/e/1FAIpQLSfTQ6Oqc_OGpKT-Ne14qyrsjr2VAatRlUGtz02mkMwGDNThiQ/viewform?pli=1 5/17
10/28/23, 6:25 PM Java M2+M3

8:->Rita has x number of choclates with her to distribute z number of chocolates to


y number of students.
(Note: z * y should be < than x )

write a java program to read x, y and z from the user and obtain number of
choclates left with Rita after distribution of z choclates to every student using
compound assignment operator.
Test Case 1 :
Input :
x = 10, z = 2, y = 4
Output :
number of chocolates left after distribution is 2

Test Case 2 :
Input :
x = 5, z = 1 , y = 4
Output :
number of chocolates left with rita after distribution is 1

import java.util.Scanner;

class ChocolateDistribution {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.print("Enter total number of chocolates (x): ");


int x = scanner.nextInt();
System.out.print("Enter number of students (y): ");
int y = scanner.nextInt();
System.out.print("Enter number of chocolates to distribute (z): ");
int z = scanner.nextInt();
int chocolateLeft = (z * y <= x) ? (x -= z * y) : x;
System.out.println("Number of chocolates left after distribution is " + chocolateLeft);

}
}

https://docs.google.com/forms/d/e/1FAIpQLSfTQ6Oqc_OGpKT-Ne14qyrsjr2VAatRlUGtz02mkMwGDNThiQ/viewform?pli=1 6/17
10/28/23, 6:25 PM Java M2+M3

9:->Trace the following pseudocode and give the ouput


int i = 10 ;
int j = i-- ;
int k = i-- + ++j ;
print( --i + ", " + ++j + ", " + --k ) ;

7,12,19

10:->assume you have stored an alphabet in a container, how do we update the


container with the previous alphabet? Write a program to store an alphabet in a
variable and update it to it's previous and print the updated variable.

import java.util.Scanner;

class Alphbet{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the character : ");
char alph = sc.next().charAt(0);
char previous = (char) (alph - 1);
System.out.println("Original alphabet: " + alph);
System.out.println("Updated to the previous alphabet: " + previous);

}
}

11:->current age of Luther is 21, what will be his age after his upcomming birthday?
Write a program to store his current age, and update his age after his birthday
using increment operator.

class Updateage {
public static void main(String[] args) {
int currentAge = 21;
currentAge++;
System.out.println("Luther's age after his upcoming birthday : " + currentAge);
}
}

https://docs.google.com/forms/d/e/1FAIpQLSfTQ6Oqc_OGpKT-Ne14qyrsjr2VAatRlUGtz02mkMwGDNThiQ/viewform?pli=1 7/17
10/28/23, 6:25 PM Java M2+M3

12: ->int m=1010, n=1010;


System.out.println(m++ / ++n * n-- / --m); (note : / =division)

13:-> int a, b, exp = 10;


a = b = 5;
exp *= ++a * 10 / b++ + --a;
System.out.println("exp = " +exp);

170

14:->Trace the following pseudocode and give the Output

int a = 10 ;
int b = 11 ;
int res = ++a == b ? 0 : 1 ;
print( res ) ;

res = 0

15:-> int x = 5, y = 2, exp = 10;


exp %= x + ( x > 6 ? ++y : --y);
System.out.println("exp = " +exp);

exp = 4

https://docs.google.com/forms/d/e/1FAIpQLSfTQ6Oqc_OGpKT-Ne14qyrsjr2VAatRlUGtz02mkMwGDNThiQ/viewform?pli=1 8/17
10/28/23, 6:25 PM Java M2+M3

16:->Trace the following pseudocode and give the Output

int age = 18 ;
int eligibility = 18 ;
print( age-- > eligibility ? "eligible" : "not eligible" ) ;

not eligible

17:->Write a program to read 2 integer numbers from the user and obtain the
largestr number using conditional operator.

Test Case 1:
Input :
num1 : 10
num2 : 20
Output : 20

Test Case 2:
Input :
num1 : -30
num2 : -15
Output: -15

import java.util.Scanner;
class Integer{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the frist number : ");
int a = sc.nextInt();
System.out.println("Enter the Second number : ");
int b = sc.nextInt();

String s = (a > b) ? a+" : Is largest number":b+" : Is largest number";


System.out.println(s);
}
}

https://docs.google.com/forms/d/e/1FAIpQLSfTQ6Oqc_OGpKT-Ne14qyrsjr2VAatRlUGtz02mkMwGDNThiQ/viewform?pli=1 9/17
10/28/23, 6:25 PM Java M2+M3

18:->Write a program to read an integer from the user and check whether the
number is even number or odd number.

Test Case 1:
Input :
num1 : 10
Output :
even

Test Case 2:
Input :
num1 : -31
Output:
odd

import java.util.Scanner;
class Even_odd{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the frist number : ");
int a = sc.nextInt();

String s = (a%2==0) ? a+ " : It's Even number":a+" : Its Odd number";


System.out.println(s);
}
}

https://docs.google.com/forms/d/e/1FAIpQLSfTQ6Oqc_OGpKT-Ne14qyrsjr2VAatRlUGtz02mkMwGDNThiQ/viewform?pli=1 10/17
10/28/23, 6:25 PM Java M2+M3

19:->Amrita decided to gift her kid rohan with a cash prize of 10 times the cost of a
dairy milk chocolate after his final exam. She also said
rohan if he scores more than his friend ajay, she would give a cash price of 20 time
the dairy milk chocolate instead of 10 times.
Write a logic to read the marks of rohan and ajay, also generate the cash price
rohan would receive if the cost of one dairay milk chocolate is
15 Rs.

import java.util.Scanner;
class CashPrize {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int Chocolatecost = 15;
System.out.print("Enter Rohan's score: ");
int rohanScore = scanner.nextInt();
System.out.print("Enter Ajay's score: ");
int ajayScore = scanner.nextInt();
int cashPrize = (rohanScore > ajayScore) ? (20 * Chocolatecost) : (10 * Chocolatecost);

System.out.println("Rohan's cash prize is: " + cashPrize + " Rs");

}
}

https://docs.google.com/forms/d/e/1FAIpQLSfTQ6Oqc_OGpKT-Ne14qyrsjr2VAatRlUGtz02mkMwGDNThiQ/viewform?pli=1 11/17
10/28/23, 6:25 PM Java M2+M3

20:->Write a java program in java to print the name of the day according the day
number given by the user
ex:=>
1="monday"
2="tuesday"
3="wednesday"
4="thursday"
5="friday"
6=saturday"
7="sunday"

import java.util.Scanner;
class Day{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number : ");
int a = sc.nextInt();

String s = (a==1)?"Monday":((a==2) ? "Tuesday" : ((a==3) ? "Wednesday" : (a==4) ?


"Thursday" :
(a==5) ? "Friday" :((a==6) ? "Saturday" : ((a==7) ? "Sunday" : "Invalid"))));
System.out.println(s);
}
}

https://docs.google.com/forms/d/e/1FAIpQLSfTQ6Oqc_OGpKT-Ne14qyrsjr2VAatRlUGtz02mkMwGDNThiQ/viewform?pli=1 12/17
10/28/23, 6:25 PM Java M2+M3

21:=>Write a java program to calculate area of the of the trapizium whose hight ,
length of both side is given by the user

import java.util.Scanner;
public class TrapeziumArea {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the height of the trapezium: ");
double height = scanner.nextDouble();
System.out.print("Enter the length of the first base: ");
double b1 = scanner.nextDouble();
System.out.print("Enter the length of the second base: ");
double b2 = scanner.nextDouble();
double area = 0.5 * (b1 + b2) * height;
System.out.println("The area of the trapezium is: " + area);

}
}

https://docs.google.com/forms/d/e/1FAIpQLSfTQ6Oqc_OGpKT-Ne14qyrsjr2VAatRlUGtz02mkMwGDNThiQ/viewform?pli=1 13/17
10/28/23, 6:25 PM Java M2+M3

22:->Write a java program to print the suitable massage to the user given
temprature for a city
temrature massage=>
temprature range massage

temp<0 and temp<=10 verry cold


temp>10 and temp<=20 cold
temp>20 and temp<=25 moderate
temp>25 and temp<=35 summer
temp>35 and temp<=40 temprature high
temp>40 temprature is too high

import java.util.Scanner;
class Temprature{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Temrature : ");
int temp = sc.nextInt();

String s = (temp<0 && temp<=10)?"Very Cold":((temp>10 && temp<=20) ? "Cold" :


((temp>20 && temp<=25) ? "Moderate" : (temp>25 && temp<=35) ? "Summer" :
(temp>35 && temp<=40) ? "Temprature High" :((temp>40) ? "temprature is too high" :
"Invalid")));
System.out.println(s);
}
}

https://docs.google.com/forms/d/e/1FAIpQLSfTQ6Oqc_OGpKT-Ne14qyrsjr2VAatRlUGtz02mkMwGDNThiQ/viewform?pli=1 14/17
10/28/23, 6:25 PM Java M2+M3

23:->Write a java program to convert the given temprature by the user from
fahrenhite to celcious

import java.util.Scanner;

class TempConvert {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.print("Enter temperature in Fahrenheit: ");


double fahrenheit = scanner.nextDouble();
double celsius = (fahrenheit - 32) * 5.0/9.0;
System.out.println("The temperature in Celsius is: " + celsius + " degree celcius");

}
}

24:->Write a java program to take indian rupees input from the user and convert
that ammount in dollar ,yen, euro and rubel currency.

import java.util.Scanner;
class CurrencyConverter {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the amount in INR: ");
double inrAmount = scanner.nextDouble();
double dollarRate = 0.014;
double yenRate = 1.48;
double euroRate = 0.011;
double rubRate = 1.08;
double dollarAmount = inrAmount * dollarRate;
double yenAmount = inrAmount * yenRate;
double euroAmount = inrAmount * euroRate;
double rubAmount = inrAmount * rubRate;

System.out.println("Amount in Indian INR: " + inrAmount);


System.out.println("Amount in Dollars: " + dollarAmount);
System.out.println("Amount in Yen: " + yenAmount);
System.out.println("Amount in Euro: " + euroAmount);
System.out.println("Amount in Rubles: " + rubAmount);
}
}

https://docs.google.com/forms/d/e/1FAIpQLSfTQ6Oqc_OGpKT-Ne14qyrsjr2VAatRlUGtz02mkMwGDNThiQ/viewform?pli=1 15/17
10/28/23, 6:25 PM Java M2+M3

25:-> Write a java program to take angel degree value input from user and convert
that in min and sec(both) and print the result;

import java.util.Scanner;

class Degree {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the angle in degrees: ");
double deg = scanner.nextDouble();
double totalMinutes = deg * 60;
int min = (int) totalMinutes;
double sec= (totalMinutes - min) * 60;

System.out.println("Degrees: " + deg);


System.out.println("Minutes: " + min);
System.out.println("Seconds: " + sec);

}
}

Submit Clear form

Never submit passwords through Google Forms.

This content is neither created nor endorsed by Google. Report Abuse - Terms of Service - Privacy Policy

Forms

https://docs.google.com/forms/d/e/1FAIpQLSfTQ6Oqc_OGpKT-Ne14qyrsjr2VAatRlUGtz02mkMwGDNThiQ/viewform?pli=1 16/17
10/28/23, 6:25 PM Java M2+M3

https://docs.google.com/forms/d/e/1FAIpQLSfTQ6Oqc_OGpKT-Ne14qyrsjr2VAatRlUGtz02mkMwGDNThiQ/viewform?pli=1 17/17

You might also like