Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: an idea for a method

  1. #1
    Junior Member
    Join Date
    Sep 2019
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default an idea for a method

    Im not sure that im posting in the the right place.
    I writing a code that should recieve a string ("HELLO"), make it upper case, then print the whole string as huge as:
    A =
    a
    a a
    aaaaa
    a a
    a a
    I think only of the way of comparing by Switch each letter (such as 'Z' is 90), as long as i do a "for loop" and check by string[0] to string [max], or by "char array".
    I tried so many times and used many ways but nothing seems promising yet. Please give me an idea for finish it.

    This is my last try for only letters A and B, hope you will understand.

    	public static void main(String[] args) {
    		Scanner input = new Scanner(System.in);
    		char x[] = input.nextLine().toCharArray();
    		String a1, a2, a3, a4, a5, b1, b2, b3, b4, b5, c1, c2, c3, c4, c5, d1, d2, d3, d4, d5;
     
    	word1(x[0]);//first letter
    	word2(x[1]);
    	word3(x[2]);
    	word4(x[3]);
    	System.out.println(new String(a1)+new String(b1)+new String(c1)+new String(d1));
    	System.out.println(new String(a2)+new String(b2)+new String(c2)+new String(d2));
    	System.out.println(new String(a3)+new String(b3)+new String(c3)+new String(d3));
    	System.out.println(new String(a4)+new String(b4)+new String(c4)+new String(d4));
    	System.out.println(new String(a5)+new String(b5)+new String(c5)+new String(d5));
    	}
     
     
    private static void word1(char c){//bring first letter!
    	String a1, a2, a3, a4, a5;
    	switch (c) {
    	case 90:
    		a1 = "    a    ";
    		a2 = "   a a   ";
    		a3 = "  aaaaa  ";
    		a4 = " a     a ";
    		a5 = " a     a ";
    		break;
    	case 71:
    		a1 = "bbb  ";
    		a2 = "b  b ";
    		a3 = "bbb  ";
    		a4 = "b  b ";
    		a5 = "bbb  ";
    		break;
    	}
    }
    private static void word2(char c){//bring first letter!

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: an idea for a method

    I don't know of any way to get a String with letters in the shape of a letter than the one you chose. One simplification might be to put the Strings into an array instead of having 5 separate Strings:
           String[] letterA = {"    a    ",
                         		"   a a   ",
                         		"  aaaaa  ",
                         		" a     a ",
                                    " a     a "};
            for(String line : letterA) {   //  Print the lines in a letter
               System.out.println(line);  
            }
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2019
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: an idea for a method

    Quote Originally Posted by Norm View Post
    I don't know of any way to get a String with letters in the shape of a letter than the one you chose. One simplification might be to put the Strings into an array instead of having 5 separate Strings:
           String[] letterA = {"    a    ",
                         		"   a a   ",
                         		"  aaaaa  ",
                         		" a     a ",
                                    " a     a "};
            for(String line : letterA) {   //  Print the lines in a letter
               System.out.println(line);  
            }
    I will do a "switch" loop with all the letters by cases.
    The problem is that each letter has 5 lines, and Im printing from left to right - so i can write like this (in big letters):
    H
    E
    L
    L
    O
    If I would wanted to do this then I'd finish it already.
    I changed the code and maybe now it will be more clear:
    package sos;
    import java.util.Scanner;
     
    public class brb {
     
    	public static void main(String[] args) {
    		Scanner input = new Scanner(System.in);
    		String d=""; //for method's return
    		System.out.println("enter a string: ");
    		String x = input.nextLine();
    		String line1="", line2="", line3="", line4="", line5="";
    		char y;
     
    		for (int i=0; i<=x.length(); i++) {
    			y = x.charAt(i);
    			word(y);
    			line1=line1+d.substring(0,7);
    			line2=line2.concat(d.substring(8,15));
    			line3=line3.concat(d.substring(16,23));
    			line4=line4.concat(d.substring(24,31));
    			line5=line5.concat(d.substring(32,39));
     
    			//take 8 chars from 'd' and put them in 'line1-5'
    		}
     
     
    	System.out.println(line1);
    	System.out.println(line2);
    	System.out.println(line3);
    	System.out.println(line4);
    	System.out.println(line5); //print out the full string
    	}
     
     
    private static String word(char y){//bring first letter!
    	String d="";
    	switch (y) {
    	case 41:
    		d=d.concat( "   a    "); // sum of 8 chars
    		d=d.concat( "  a a   ");
    		d=d.concat( " aaaaa  ");
    		d=d.concat( "a     a ");
    		d=d.concat( "a     a ");
    		break;
    	case 42:
    		d=d.concat( "bbb     ");
    		d=d.concat( "b  b    ");
    		d=d.concat( "bbb     ");
    		d=d.concat( "b  b    ");
    		d=d.concat( "bbb     ");
    		break;
     
    		/*cases 43-90 for 'C'-'Z' (inside 'word' method)
    		 * 
    		 * 
    		 */
     
    	}
    	return d;
    }
     
     
    }
     
     
    /*
    import java.util.Scanner;
     
    Scanner input = new Scanner(System.in);
    char word[] = input.nextLine().toUpperCase().toCharArray(); //CAPITAL LETTERS!
    int max = word.length-1;
    char x[] = input.nextLine().toCharArray();
    */

    Im pretty sure I did a tone of mistakes with "char" and "String", but that shows my problem as combining lines of each letter with the previous one.
    Thanks!

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: an idea for a method

    Do you have further questions about your program?

    Note: The case statements can be code using the char, they do not have to be coded as ints:
       case 'a':
       case 'A':
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Sep 2019
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: an idea for a method

    Quote Originally Posted by Norm View Post
    Do you have further questions about your program?

    Note: The case statements can be code using the char, they do not have to be coded as ints:
       case 'a':
       case 'A':
    Yes, Im asking for an idea of how doing that.
    A friend told me earlier about an "image" you can create and put each "big letter" in that image then print them all in the same line?
    case statements - noted.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: an idea for a method

    how doing that.
    Sorry I don't understand what it is you are trying to do. What is the "that"?
    My suggestion was to put each letter into an array of lines and then print the contents of the arrays one line at a time.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. [SOLVED] idea
    By josselynmedina95 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 22nd, 2014, 03:29 PM
  2. Almost got no idea how to do this! Need some H E L P!
    By maronski in forum Loops & Control Statements
    Replies: 6
    Last Post: July 30th, 2012, 10:23 PM
  3. Idea's on what else to add?
    By CodyReuille in forum Java Theory & Questions
    Replies: 2
    Last Post: October 14th, 2011, 04:34 PM
  4. need help with my idea!
    By frostwing in forum Object Oriented Programming
    Replies: 3
    Last Post: February 10th, 2011, 09:53 AM
  5. No idea what to do for this
    By jwb4291 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: July 18th, 2010, 07:16 PM