AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



corejava-programming: Program to print cabin number

Given a list of people's names and the number of people sitting in a cabin, take as input a person's name and print his cabin number. Cabins are numbered as 1, 2, 3....

Input Specification:

First line should accept a number for "Total number of people".

Second line should accept a number for "Number of people per cabin"

From third line, program should accept "n" number of people´s names last line should accept a name to search

Sample Input 1:

8

3

Vivek

Swaroop

Suman

Usha

Vinod

Ajesh

Soumya

Pragya

Usha

Sample Output 1 :

Usha is in Cabin 2

Sample Input 2:

6

2

Amitabh

Sharukh

Salman

Abishek

Hrithik

Rohit

Shiva

Sample Output 2 :

Shiva is not in the list

corejava x 352
programming x 168
Posted On : 2018-01-16 13:53:35.0
profile Xda Coder - anyforum.in Xda Coder
1300
up-rate
2
down-rate

Answers


import java.util.Scanner;

class PersonCabin
{
public static void main(String args[]){
int n,k;
String name;
Scanner sc=new Scanner(System.in);
n=Integer.parseInt(sc.nextLine());
k=Integer.parseInt(sc.nextLine());
String s[]=new String[n];
for(int i=0;i<n;i++){
s[i]=sc.nextLine();
}
name=sc.nextLine();
int ans=0;
boolean flag=true;
for(int j=0;j<s.length;j++){
if(s[j].equals(name)){
ans=j/k+1;;
flag=false;
break;
}
}
if(flag){
System.out.println(name+" is not in the list");
}else{
System.out.println(name+" is in Cabin "+ans);
}
}

}

Posted On : 2018-01-23 16:45:20
Satisfied : 2 Yes  0 No
profile Divesh - anyforum.in Divesh
101180
Reply This Thread
up-rate
5
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in