Skip to main content

Java Interview Question || Top 10 question in java interview || by Er prince kumar

          Java Interview Question in java

1.1.Write a program 

   Take one n amount througth the user and distribute this amount 

   until amount will be zero/end. all amunt distribute in the run time

   if amount is insufficent to the last user than display unsufficent

   amount , avilable amount is 200 . Enter your amount 200 ok thanks

====================================
import java.util.Scanner;
class ATMAmount{
public static void main(String args[]){
    int amt;
Scanner sc=new Scanner(System.in);
System.out.print("Deposit Amount:");
amt=sc.nextInt();
int useramt=0;
while(true){
     System.out.print("Withdrawal Amount:");
    useramt=sc.nextInt();
if(amt>=useramt){
       amt=amt-useramt;
}
else if(amt<=0) {
     System.out.println("Sorry..? Balance not Avilable ");
break;
}
else{
       System.out.println("Unsufficent Amunt \n Avilable Amt="+amt);
}
    
}
}
}










2. Write a java program
   You have a one shop in this show you are selling the laptop, category is dell,hp,lenovo
    ,accer . find the maximum sell which laptop. if dell and hp are selling the same
     than give the highest priority of the dell laptop. other wise print the maximum
selling laptop name and how many laptop is sell.
===================================

import java.util.Scanner;
class ShopSellLeptop{
  public static void main(String argg[]){
  Scanner sc=new Scanner(System.in);
  int dell,hp,lenovo,accer;
    System.out.println("Enter Number of Avilable in dell,hp,lenovo,accer laptop in shop:");
dell=sc.nextInt();
hp=sc.nextInt();
lenovo=sc.nextInt();
accer=sc.nextInt();
String laptop=null;
int d=0,h=0,l=0,a=0;
while(true){
        System.out.println("which laptop do you want:");
         laptop=sc.next();
if(laptop.equalsIgnoreCase("dell")){
if(dell>0){
               dell=dell-1;
   d++;
    System.out.println("your laptop choice:"+laptop+"Take your laptop thanks");
}
else 
                 System.out.println("Sorry..? "+laptop+" is not avilable in shop");
           
}
  else if(laptop.equalsIgnoreCase("hp")){
if(hp>0){
               hp=hp-1;
   h++;
    System.out.println("your laptop choice:"+laptop+"Take your laptop thanks");
}
else 
                 System.out.println("Sorry..? "+laptop+" is not avilable in shop");
           
}
  else if(laptop.equalsIgnoreCase("lenovo")){
if(lenovo>0){
                lenovo=lenovo-1;
l++;
    System.out.println("your laptop choice:"+laptop+"Take your laptop thanks");
}
else 
                 System.out.println("Sorry..? "+laptop+" is not avilable in shop");
           
}
else  if(laptop.equalsIgnoreCase("accer")){
if(accer>0){
               accer=accer-1;
   a++;
    System.out.println("your laptop choice:"+laptop+"Take your laptop thanks");
}
else 
                 System.out.println("Sorry..? "+laptop+" is not avilable in shop");
           
}
  else if(laptop.equalsIgnoreCase("stop")){
  break;
}
  else System.out.println("Invalid name of laptop");

}
    System.out.println("Dell sale\t\t:"+d);
System.out.println("Hp sale\t\t\t:"+h);
System.out.println("Lenovo sale\t\t:"+l);
System.out.println("Accer sale\t\t:"+a);
if(dell>hp&& hp>lenovo&& lenovo>accer){
       System.out.println("Dell is sale maximum:"+dell);
}
    if(dell==hp){
       System.out.println("Dell is sale maximum:"+dell);  
}








  }
}



==========================================================
Enter Number of Avilable in dell,hp,lenovo,accer laptop in shop:
4 5 6 10
which laptop do you want:
dell
your laptop choice:dellTake your laptop thanks
which laptop do you want:
accer
your laptop choice:accerTake your laptop thanks
which laptop do you want:
hp
your laptop choice:hpTake your laptop thanks
which laptop do you want:
hp
your laptop choice:hpTake your laptop thanks
which laptop do you want:
hp
your laptop choice:hpTake your laptop thanks
which laptop do you want:
dell
your laptop choice:dellTake your laptop thanks
which laptop do you want:
lenovo
your laptop choice:lenovoTake your laptop thanks
which laptop do you want:
dell
your laptop choice:dellTake your laptop thanks
which laptop do you want:
dell
your laptop choice:dellTake your laptop thanks
which laptop do you want:
dell
Sorry..? dell is not avilable in shop
which laptop do you want:
dell
Sorry..? dell is not avilable in shop
which laptop do you want:
stop
Dell sale               :4
Hp sale                 :3
Lenovo sale          :1
Accer sale             :1
Press any key to continue . . .

Comments

Popular posts from this blog

How to Send OTP in Mobile Number | login with OTP mobile Number | How to send OTP in mobile no with Spring Boot APP

   ðŸ˜‚               Login with Mobile Number OTP ---------------------------------------------------------------------------- If you want to develop a project to log in with OTP mobile Number in Spring Boot Applications then this post for you. In this post, I am going to use some other service to send the OTP in mobile number. we have to use it in this project spring boot. we are going to use Twilio to send SMS. we are going to use a web socket to send the data from the browser to the SMS gateway. Oracle Database for store the user details. <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> <version>2.3.3.RELEASE</version> </dependency> <dependency> <groupId>com.twilio.sdk</grou

Spring Boot With MySQL Database connection with Examples | MySQl Database Configuration with Spring Boot Projects

 ðŸ˜ƒ MySQL Database Configuration with Spring Boot Projects  In this article, we are going to introduce How to connect MySQL Database with the Spring Boot project. pom.xml   <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.projectlombok</gro

How can we create Auto generated field or ID for mongodb using spring boot

😂 How can we create an Auto-generated field or ID for MongoDB using spring boot? First Create One Application Like Mongodb_sequence-id-generator Pom.XML <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-mongodb</artifactId> </dependency> <dependency> <groupId>de.flapdoodle.embed</groupId> <artifactId>de.flapdoodle.embed.mongo</artifactId> </dependency> User.java package com.app; import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Transient; import org.springframework.data.mongodb.core.mapping.Document; @Document(collection = "users_db") public class User { @Transient public static final String SEQUENCE_NAME = &