Topics Index

Program To Assign Hostel Block

If you need explanation Read this topic

If you need Answer Take test on this topic

Write a program to print the hostel block depending upon the direction of the state the student belongs and whether the student is woman or not. The directions are 'N' for North, 'E' for East, 'W' for West and 'S' for South.

Input (Character, Boolean) Printed Output
'N', false North Men's Block
'E', true East Women's Block
'W', false West Men's Block
'S', true South Women's Block

class AssignHostelBlock
    public static void main(String s[])
        assignHostelBlock('N', false);


    public static void assignHostelBlock(char direction, boolean woman)

Topic: Using Break In for Loop To Exit

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

The switch statement is Java’s multiway branch statement. It provides an easy way to dispatch execution to different parts of your code based on the value of an expression. As such, it often provides a better alternative than a large series of if-else-if statements.swich expression allows char primitive we can easily find direction using this switch statement. inside each switch use one if else condition to check true or false .for that we initially need to declare  char and Boolean variables. char var for switch expression, Boolean for find women or men block.thn  use break statement in each case to terminate after the case execution.

Posted by Maheshwari Natarajan    2014-12-08 18:41:36

This dose is now closed and the winners are Sai Ram,  for 'First Correct Comment', Maheshwari Natarajan,  for 'Second Correct Comment'. The 'lucky liker' is Sai Veerendra. Please login into Merit Campus using facebook, to claim your recharge. Go to to raise the recharge.

Posted by Merit Campus    2014-12-09 03:35:27

© meritcampus 2019

All Rights Reserved.

Open In App