i'm wanting to do a for loop on the last line

System.out.println(host + "\t" + status);

of this bit of code so that when i replace

String host = "server";

with something like this:

String hostarray[] = {"pc","server","pc2","another","etc"};

that i get output that looks like this:
Server Up?
pc true
server false
pc2 true
another true
etc true

and this is where i am... and no, i'm no programmer...

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

class isup {	
	public static void main (String args[]) throws 
	 UnknownHostException, IOException{
		String host = "server"; // pc or server name
			int timeOut = 3000; // milliseconds
			boolean status = InetAddress.getByName(host).isReachable(timeOut); // status is true or false
			System.out.println("Server\t\tUp?"); // table heading
			System.out.println(host + "\t" + status); // list of servers and up or not - the tab thing needs some work...

thanks in advance... :)

6 Years
Discussion Span
Last Post by NormR1

// list of servers and up or not - the tab thing needs some work...

The comment says it all.
Where are the arrays with the servers and the Up/down settings?
You show one named: hostarray, now you need one for the status.

Read up on how to use a for() loop
and how to use an index to get an element out of an array.
Put the two together using the for() loop's iterating int value as the index to the array.


there need be no array for up or down as
boolean status = InetAddress.getByName(host).isReachable(timeOut);
returns true or false (stored in status)
and that's all i need...

but like you say, looks like i have a lot of reading / figuring out to do...
was just hoping someone had a quick resolve...


Have you used Search on the forum for samples of 'for' statements?
There must be hundreds. Try looking for "for(int"

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.