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 . . .
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
Post a Comment