java codes
//if else code
package studyopedia;
public class ifff {
public static void main(String[] args) {
int a=20,b=10;
if(a<b) {
[Link]("smaller value is a" +a);
}else {
[Link]("smaller value is b" +b);
}
}
//1dollar=100cents write a program to take 2 percens inputs d1,c1 and
d2,c2 and print the total dollars and cents
package user;
public class problem2 {
public static void main(String[] args) {
int d1=10;
int c1=90;
int d2=40;
int c2=20;
int c=c1+c2;
int cents=c%100;
int dol=c/100;
int d=d1+d2+dol;
[Link]("dollars" +d);
[Link]("cents "+cents);
//take 3 digit value and using division and modulus reverse the number
package user;
public class prblm {
public static void main(String[] args) {
int a=123;
int b=a%10;
int c=a/10;
int d=c%10;
int e=c/10;
int res=b*100 + d*10 +e;
[Link]("res is"+res);
}
//details in swiggy
package user;
public class details {
public static void main(String[] args) {
String cust_name = "siri";
float order_total = 55.7f;
byte num = 127;
long phone_no = 1234567879l;
double number = 199.99;
int delivery_time = 30;
boolean status = true;
[Link]("name is" +cust_name);
[Link]("order total is" +order_total);
[Link]("delivery time" +delivery_time);
[Link]("status is" +status);
[Link]("phone number is " +phone_no);
[Link](" number is " +number);
[Link](Byte.MIN_VALUE);
[Link](Byte.MAX_VALUE);
[Link]("byte value" +num);
[Link](Integer.MIN_VALUE);
}
//inputs are year and month,need to check whether it is leap year and
print no of days in feb,and remaining no. of days for each month
package studyopedia;
public class problm4 {
public static void main(String[] args[]) {
int y=2012;
int m=1;
if(m==2) {
if(y%4==0 && y%100!=0 || y%400==0) {
[Link]("No of days 28");
}else {
[Link]("No of days 29");
}
} else if(m==1 || m==3 || m==5 || m==7 || m==8 || m==10 ||
m==12) {
[Link]("No of days = 31");
}else {
[Link]("No of days = 30");
}
1.
import [Link].*;
//
public class Main {
public static void main(String[] args) {
boolean traffic=true;
int del_time=30;
if(traffic==true){
del_time+=10;
[Link]("increased delivery time is" +del_time);
}else{
[Link]("no change in dlivery time");
}
}
//9 Session
//Exercise 1.
import [Link].*;
public class Main {
public static void main(String[] args) {
int burger=150;
int fries=80;
int amount=burger+fries;
if(amount>200){
int total= amount - amount*10/100;
[Link]("total amount is" +total);
}else{
[Link]("amount is "+amount);
}
}
}
//9 session
//Exercise [Link] Delivery Partner Orders
import [Link].*;
public class Main {
public static void main(String[] args) {
int orders=2;
orders++;
[Link]("enter whether the order is delivered or not");
Scanner sc=new Scanner([Link]);
boolean delivered=[Link]();
if(delivered==true){
orders--;
}
[Link]("No of remaining orders" +orders);
}
}
//session 9
//exercise 3
import [Link].*;
public class Main {
public static void main(String[] args) {
int order=550;
String rest_name="Bistro Restaurant";
boolean ptnr_rest=true;//assuming given is a partner rest:)
if(order>500 && ptnr_rest){
[Link]("customer qualifies for the offer");
}else{
[Link]("customer is not qualified for the offer");
}
}
}
//session 9
//exercise 4
import [Link].*;
public class Main {
public static void main(String[] args) {
int del_time=30;
Scanner sc=new Scanner([Link]);
boolean traffic=[Link]();
if(traffic==true){
del_time+=15;
}
[Link]("Updated delivery time is" +del_time);
}
}
//practice Exercise1:Applyig Service Charge
import [Link].*;
public class Main {
public static void main(String[] args) {
int total_cost=600;
float charges=total_cost*5/100;
float final_amount=total_cost+charges;
[Link]("final amount is" +final_amount);
}
}
//Practice exercise2 : Discount eligibility for New Users
import [Link];
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner([Link]);
boolean isNewUser=[Link]();
double orderValue=[Link]();
if(isNewUser==true && orderValue>300){
[Link]("user is eligible for special discount");
}
}
}
//Practic Exercise 3: Calculating Tips
import [Link];
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner([Link]);
int orderAmount=[Link]();
float tip;
if(orderAmount<500){
tip=orderAmount * 10/100;
}else{
tip=orderAmount * 15/100;
}
[Link](tip);
}
}
//Practice Exercise 4:Updating Total Orders Based on customer Feedback
import [Link].*;
public class Main {
public static void main(String[] args) {
int order_count=3;
Scanner sc=new Scanner([Link]);
int feedback=[Link]();
if(feedback>=3){
[Link]("Order count remains same" +order_count);
}else{
order_count--;
[Link]("Order count decreases by one i.e,"
+order_count);
}
}
}
//Practice Exercise 5: Adjustin Delivery Estimates for Weather Conditions
import [Link].*;
public class Main {
public static void main(String[] args) {
int del_time=30;
Scanner sc=new Scanner([Link]);
Boolean isRaining=[Link]();
if(isRaining==true){
del_time+=20;
}
[Link]("Delivery Time" +del_time);
}
}
//Session 10
//exercise 1:
import [Link];
public class Main {
public static void main(String[] args) {
[Link]("enter the input");
Scanner sc=new Scanner([Link]);
int amount=[Link]();
double total;
if(amount>1000){
total=amount-(amount*0.2);
[Link]("output" +total);
}else if(amount>500 && amount<1000) {
total = amount-(amount*0.1);
[Link]("output " +total);
}else{
[Link]("no discount is applied and output is"
+amount);
}
}
//Session 10
//Exercise 2
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner([Link]);
int distance=[Link]();
int charge;
if(distance>10){
charge=100;
[Link]("Delivery charge : "+charge);
}else if(distance>5 && distance<10){
charge=50;
[Link]("Delivery charge : "+charge);
}else{
[Link]("Free Delivery");
}
}
}
//session 10
//Exercise 3(Doubt)
import [Link];
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner([Link]);
int time=[Link]();
if(time >= 18 && time <= 21){
[Link]("15% discount applied");
}else if(time >= 24 && time <= 18){
[Link]("10% discount applied");
}else{
[Link]("No discount applied");
}
}
}
//session10
//practice1
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner([Link]);
int order=[Link]();
float pay;
if(order>500){
pay=order-order*10/100;
}else if(order>300 && order<500){
pay=order-order*5/100;
}else{
pay=order;
}
[Link]("final payable amount is "+pay);
}
}
//session10
//practice 2
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner([Link]);
int distance=[Link]();
int charge;
if(distance<3){
charge=20;
[Link]("Delivery charge : "+charge);
}else if(distance>3 && distance<6){
charge=40;
[Link]("Delivery charge : "+charge);
}else{
charge=60;
[Link]("Delivery charge : "+charge);
}
}
}
//Session 10
//Practice 3
import [Link];
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner([Link]);
int time=[Link]();
if(time<11){
[Link]("Morning Delivery");
}else if(time >= 11 && time <= 18){
[Link]("Afternoon Delivery");
}else{
[Link]("Evening Delivery");
}
}
}
//Patterns by using for loops
import [Link];
public class Main {
public static void main(String[] args) {
Scanner obj=new Scanner([Link]);
[Link]("enter no. of rows");
int r=[Link]();
[Link]("enter [Link] columns");
int c=[Link]();
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
[Link]("*");
}
[Link]();
}
}
}
//pattern
//*
//**
///***
import [Link];
public class Main {
public static void main(String[] args) {
Scanner obj=new Scanner([Link]);
[Link]("enter no. of rows");
int r=[Link]();
[Link]("enter [Link] columns\n");
int c=[Link]();
for(int i=1;i<=r;i++){
for(int j=1;j<=i;j++){
[Link]("*");
}
[Link]();
}
}
}
//pattern
***
**
*
import [Link];
public class Main {
public static void main(String[] args) {
Scanner obj=new Scanner([Link]);
[Link]("enter no. of rows");
int r=[Link]();
[Link]("enter [Link] columns\n");
int c=[Link]();
for(int i=r;i>=1;i--){
for(int j=1;j<=i;j++){
[Link]("*");
}
[Link]();
}
}
}
//pattern
***
* *
***
import [Link];
public class Main {
public static void main(String[] args) {
Scanner obj=new Scanner([Link]);
[Link]("enter no. of rows");
int r=[Link]();
[Link]("enter [Link] columns\n");
int c=[Link]();
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
if(i==2 && j==2){
[Link](" ");
}else{
[Link]("*");
}
}
[Link]();
}
}
}
/print the given pattern
/* * * * *
* * *
* * *
* * *
* * * * *
import [Link];
public class Main {
public static void main(String[] args) {
Scanner obj=new Scanner([Link]);
[Link]("enter no. of rows");
int r=[Link]();
[Link]("enter [Link] columns\n");
int c=[Link]();
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
if(i==1 || i==r || j==1 ||j==c || i==j){
[Link](" * ");
}else{
[Link](" ");
}
}
[Link]();
}
}
}
//pattern
* * * * *
* * * *
* * *
* * * *
* * * * *
import [Link];
public class Main {
public static void main(String[] args) {
Scanner obj=new Scanner([Link]);
[Link]("enter no. of rows");
int r=[Link]();
[Link]("enter [Link] columns\n");
int c=[Link]();
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
if(i==1 || i==r || j==1 ||j==c || i==j || i+j==r+1){
[Link](" * ");
}else{
[Link](" ");
}
}
[Link]();
}
}
}