Skip to content

Instantly share code, notes, and snippets.

@TabsPH
Created October 11, 2012 03:22
Show Gist options
  • Select an option

  • Save TabsPH/3869963 to your computer and use it in GitHub Desktop.

Select an option

Save TabsPH/3869963 to your computer and use it in GitHub Desktop.
Array of Concertgoer
import java.util.Scanner;
public class Concertgoer {
static Scanner sn = new Scanner( System.in );
public static void main(String[] args) {
String emoticon[] = new String[20];
System.out.print("Enter number of concertgoers:" );
int n = sn.nextInt();
if( n < 20 ) {
for( int i=0; i<n; i++ ) {
System.out.printf("Enter concertgoers %d: ", i+1 );
emoticon[i] = checkConcertgoer( sn.next(), i );
}
displayAllConcertgoer( emoticon );
}
else
System.out.println("Number of concertgoers exceeded.");
}
private static String checkConcertgoer(String str, int i) {
if( str.contains( ":" ) ) {
return str;
}
else {
System.out.println("Invalid!" );
System.out.printf("Enter concertgoers: %d: ", i+1 );
checkConcertgoer( sn.next(), i );
}
return "";
}
public static void displayAllConcertgoer( String[] arr ) {
System.out.println("\n\nList of Concertgoers:");
for(int i=0; i<arr.length; i++) {
if( arr[i] != null ) {
System.out.printf( "%nConcertgoer %d: %s ", i+1, arr[i] );
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment