Java M2+M3
Java M2+M3
Java M2+M3
[email protected] Switch accounts Draft saved
Email *
Akash P. Shilimkar
M2
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();
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;
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;
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;
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
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);
}
}
https://docs.google.com/forms/d/e/1FAIpQLSfTQ6Oqc_OGpKT-Ne14qyrsjr2VAatRlUGtz02mkMwGDNThiQ/viewform?pli=1 6/17
10/28/23, 6:25 PM Java M2+M3
7,12,19
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
170
int a = 10 ;
int b = 11 ;
int res = ++a == b ? 0 : 1 ;
print( res ) ;
res = 0
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
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();
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();
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);
}
}
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();
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
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();
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);
}
}
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;
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;
}
}
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