Results 1 to 4 of 4
- 09-22-2009, 03:50 AM #1
Member
- Join Date
- Sep 2009
- Posts
- 2
- Rep Power
- 0
ASAP PLZ- Having problems with basic pattern input/output
Hey! I am new to this forum, and I am also new to java =).
I am writing a program that prompts a user to select 1 pattern out of 5. then the user needs to choose the number of lines he/she wants to display for instace:
(MENU)
PATTERN 5
1
12
123
1234
USER Selection : Pattern 5
Choose Number of Lines: 3
OUTPUT
Pattern 5
1
12
123
}
I have a basic code for a pyramid that deals with leading spaces etc.. but I don't have a clue how to use that method with my program
MY PROGRAM:
Java Code://Purpose: Displaying Patterns //Input: User's selection //Output: Messages //Author; Fares //Program: 4 //Date: 9/15/2009 // import java.util.Scanner; public class MyPatterns4{ public static void main(String[] args) { // Declarations Scanner scan = new Scanner(System.in); String outputString; int option = 1; int lines; // Paterns String patternOne; patternOne = "\n\t Pattern I \n\t 1 \n\t 12 \n\t 123 \n\t 1234 \n\t 12345 \n\t 123456"; String patternTwo; patternTwo= "\n\t Pattern II \n\t 123456 \n\t 12345 \n\t 1234 \n\t 123 \n\t 12 \n\t 1"; String patternThree; patternThree = "\n\t Pattern III \n\t 1 \n\t 21 \n\t 321 \n\t 4321 \n\t 54321 \n\t 654321"; String patternFour; patternFour = "\n\t Pattern IV \n\t 123456 \n\t 12345 \n\t 1234 \n\t 123 \n\t 12 \n\t 1"; String patternFive; patternFive = "\n\t Pattern V \n\t 1 \n\t 12 \n\t 123 \n\t 123456 \n\t 123 \n\t 12"; // Prompt the user to select a pattern outputString = "------------------------------------\n\t1 Display Pattern I\n\t2 Display Pattern II\n\t" "3 Display Pattern III\n\t4 Display Pattern IV\n\t" "5 Display Pattern V\n\t" "6 Display All Patterns\n\n\n\t" "0 Quit\n\n\n"; System.out.println(outputString); System.out.print("\tEnter your selection: "); option = scan.nextInt(); // Keep reading data until the user enters 0 while (option !=0){ while (option == 6) { outputString = "\nChoose another selections!\n"; System.out.println(patternOne); System.out.println(patternTwo); System.out.println(patternThree); System.out.println(patternFour); System.out.println(patternFive); System.out.println(outputString); outputString = "--------------------------------------------------\n\t1 Display Pattern I\n\t2 Display Pattern II\n\t" "3 Display Pattern III\n\t4 Display Pattern IV\n\t" "5 Display Pattern V\n\t" "6 Display All Patterns\n\n\n\t" "0 Quit\n\n\n"; System.out.println(outputString); System.out.print("\tEnter your selection: "); option = scan.nextInt(); } while (option != 0 && option !=6) { System.out.print("\tEnter number of lines: "); lines = scan.nextInt(); if (lines < 1 || lines > 6) { System.out.println("\tYou must enter a number from 1 to 6"); System.out.print("\tEnter number of lines: "); lines = scan.nextInt(); while (lines < 1 || lines > 6) { System.out.println("\tYou must enter a number from 1 to 6. The program will now end."); System.exit(0);} } switch (option) { case 1: // write the code to display Pattern I here outputString = "\n Choose another selection! \n"; System.out.println(patternOne); System.out.println(outputString); break; case 2: // write the code to display Pattern II here outputString = "\nChoose another selection!\n"; System.out.println(patternTwo); System.out.println(outputString); break; case 3: // write the code to display Pattern III here outputString = "\nChoose another selection!\n"; System.out.println(patternThree); System.out.println(outputString); break; case 4: // write the code to display Pattern IV here outputString = "\nChoose another selection!\n"; System.out.println(patternFour); System.out.println(outputString); break; case 5: // write the code to display Pattern V here outputString = "\nChoose another selection!\n"; System.out.println(patternFive); System.out.println(outputString); break; case 6: // the code to display all paterns outputString = "\nChoose another selections!\n"; System.out.println(patternOne); System.out.println(patternTwo); System.out.println(patternThree); System.out.println(patternFour); System.out.println(patternFive); System.out.println(outputString); break; default: outputString = "\nInvalid Selection\n"; System.out.println(outputString); break; }// end of switch outputString = "------------------------------------\n\t1 Display Pattern I\n\t2 Display Pattern II\n\t" "3 Display Pattern III\n\t4 Display Pattern IV\n\t" "5 Display Pattern V\n\t" "6 Display All Patterns\n\n\n\t" "0 Quit\n\n\n"; System.out.println(outputString); System.out.print("\tEnter your selection: "); option = scan.nextInt(); } }// end of while loop }// end of main method }// end of classLast edited by ZetaPunk; 09-22-2009 at 04:10 AM.
-
- 09-22-2009, 04:45 AM #3
Member
- Join Date
- Sep 2009
- Posts
- 2
- Rep Power
- 0
We can't cross post? Is that a wrong-doing in forums? I thought asking multiple resources was a smart thing to do. I found my problem and its fixed.
-
Congrats on getting your answer. Cross-posting is OK, but cross-posting without being upfront about it (and even better, providing links) is not.
Similar Threads
-
Assistance with packages and Object OUtput and Input
By Fuzzy in forum New To JavaReplies: 1Last Post: 08-04-2009, 12:48 PM -
Single XSD Creation for input/output
By lavanya82 in forum XMLReplies: 0Last Post: 03-13-2009, 12:02 PM -
problems with java code! (very new - need help asap!)
By sumkindafreek in forum New To JavaReplies: 1Last Post: 01-07-2009, 05:00 AM -
Basic keyboard input and edit
By BHCluster in forum New To JavaReplies: 18Last Post: 08-08-2008, 11:52 PM -
array problems need your help ASAP!
By notherand in forum New To JavaReplies: 1Last Post: 06-29-2008, 08:59 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks