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

Generate Documentation for Spring Boot API with swagger and Open API 3

 ðŸ˜‚ How to Generate Documentation for Spring Boot API project Make sure your Project having a swagger or open API 3 Dependency then only you get proper Documentation for your Service. ---------------------------------------------------------------------------- Every method or API above you have to Write Like that then only you get proper Documentation If you do everything in your Application and Run your Application and go to browse and search. . http://localhost:8080/v3/api-docs/ if you want to learn more go with this one.  Open API-3   1. For Return List of Object then you have to use this API operation  @Operation(summary = "This will fetch List of Patient Detailas base on Hospital Name") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Successfully fetch All Patient Details from Database ", content = {  @Content(mediaType = "application/json" ,array = @ArraySchema(schema =@Schema(implementation =PatientDe...

In a new programming language how can store multiple types of data in a single variable OR is it possible how can store multiple types of data in a single variable in programming langauge

In a new programming language how can store multiple types of data in a single variable  OR is it possible how can store multiple types of data in a single variable in a programming language Here In a new programming language how can store multiple types of  data in a single variable   help you make the new  concepts, you are learning a programming  Languages really very important: Ideally Yes. If you create an Array of objects. Then it's possible to store any data type with it as an object is the base class. ArrayList can hold multiple types of data, but array doesn't. Variables Variables can be thought of as ‘containers’ for data. Each variable has to  have a unique name, so that you can refer back to it in the program. By using variables, we can refer to values that have not yet been defined.  For example, we can refer to the speed of the ball in different parts of the  game code, but calculate the ball speed later based on different input...

#FibonacciNumberSeries Write a program of Fibonacci Number Series|| Fib...

Fibonacci Number Series ============================================ 0 1 1 2 3 5 8 13............. a=0; b=1; i=2; printf(a,b); while(i<=n){ c=a+b; printf(c); a=b; b=c; i++; } =========================================================================== import java.util.Scanner; class Fibonacci { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int a=0,b=1,c; System.out.print(a+" "+b); for(int i=2;i