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: Game of bus-bus

The game of bus-bus is played by a set of people, who form a circle. One of the persons in the circle has to say ´one´, the next person should say ´two´ and so on. Whenever a person gets a number, which is either divisible by seven or ends with seven, he/she should say ´Bus´ instead of the number. If the number in turn is both visible by seven and ends with a seven, then ´BusBus´ should be uttered. Any one who violates the rule is taken out of the circle and the game continues with the remaining persons. The last one remaining is the winner of the game. Write a program to simulate this game. Input to your program is n (10 <= n <= 100) upto which the above rule should be followed.

Sample input

20

Sample output

1

2

3

4

5

6

BusBus

8

9

10

11

12

13

Bus

15

16

Bus

18

19

20


corejava x 336
programming x 153
Posted On : 2016-12-23 12:49:13.0
profile Navin Kumar - anyforum.in Navin Kumar
1000
up-rate
1
down-rate

Answers


import java.util.Scanner;

public class NumberBusGame {
public static void main(String[] args) {
System.out.println("Please Enter the Number");
Scanner input=new Scanner(System.in);
int number=input.nextInt();
if(10 <= number && number <= 100){
for(Integer i=1;i<=number;i++){
if(i%7==0 && i.toString().charAt(i.toString().length()-1)==´7´){
System.out.println("BusBus");
}
else if(i%7==0 || i.toString().charAt(i.toString().length()-1)==´7´){
System.out.println("Bus");
}
else{
System.out.println(i);
}
}
}else{
System.out.println("Invalid input!");
}
}
}

Posted On : 2016-12-24 13:18:15
Satisfied : 0 Yes  0 No
profile Rishi Kumar - anyforum.in Rishi Kumar
523185319357
Reply This Thread
up-rate
4
down-rate



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