import javax.swing.JOptionPane;
import java.io.*;
public class Javax
{
public static void main(String[]args)throws IOException
{
String name = "";
String pt = "";
int[]Room = {1,1,1,1,1,0,1,1,0,0,0,0,0,0,0,1,0,1,0,1,1,1,1,1,0};
int rph = 500;
int hs = 0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String main = JOptionPane.showInputDialog("Please Enter Your Name: ");
name = String.valueOf(main);
JOptionPane.showMessageDialog(null,"Welcome to ______ "+name);
String main2 = JOptionPane.showInputDialog("How long do u wish to stay at our HOTEL" +name);
hs = Integer.parseInt(main2);
JOptionPane.showMessageDialog(null,"You Entered "+hs);
JOptionPane.showMessageDialog(null,"Here a the Currently Available Rooms")
}
}
Showing Arrays
Page 1 of 12 Replies - 142 Views - Last Post: 02 October 2012 - 04:34 PM
#1
Showing Arrays
Posted 02 October 2012 - 01:45 AM
Is there a way to show Specific arrays with the value of 1 or 0?
Replies To: Showing Arrays
#2
Re: Showing Arrays
Posted 02 October 2012 - 02:08 AM
Do you mean to ask how to show which elements of the array have the value 1 or 0? Use a loop and find the elements that have the desired value. If you just have to report a number, as in "The number of available rooms are:", then count the number of array elements with the desired value as you go through the loop.
A more OO design would be to have a class called HotelRoom that included a roomNumber and vacant properties, methods to report/change vacancy and other relevant characteristics, and then a Hotel class that returned the number of vacant rooms with room numbers.
A more OO design would be to have a class called HotelRoom that included a roomNumber and vacant properties, methods to report/change vacancy and other relevant characteristics, and then a Hotel class that returned the number of vacant rooms with room numbers.
#3
Re: Showing Arrays
Posted 02 October 2012 - 04:34 PM
You got the length of your array so u just say:
There you go. Have fun.
int k;
int []room = {.......};
for (int i = 0; i < room.length; i++) {
k = room[i]
system.out.println("Location in Array: " +i+ ". Value at Location: " +k \n);
}
There you go. Have fun.
int k = 0;of course.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|