Results 1 to 7 of 7
  1. #1
    javanab is offline Member
    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0

    Default i feel like a retard! Java noob!

    Ive been learning java for a week, my first programming language ever and im loving it. Im 31y and learning it as a hobby, yesterday while on bed, couldnt sleep i tought to myself, it would be a good excercise if i made a program where i would input the side of a square, then make the square representation.

    Anyway i tought i would do this like in 10m, i spent 3hours till i got it right, feel a complete retard and my motivation is damm low right now.


    Java Code:
    import java.util.Scanner;
    
    public class quadrado {
    
    	public static void main(String[] args) {
    
    		
    		Scanner input = new Scanner(System.in);
    		int quadrado;
    		System.out.println("Insert Square Size");
    		quadrado = input.nextInt();
    	
    		int counter = 1;
    		int total=1;
    		
    		
    		while(counter<quadrado){
    			
    			counter++;	
    			total++;
    			
    			
    			System.out.print("O   ");
    		
    
    			
    		if(counter==quadrado){
    			
    			System.out.println("O   ");
    			if((total)==(Math.pow(quadrado, 2))){break;}
    			
    			counter=1;
    			total++;
    		}
    		}
    	}
    }

  2. #2
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    392
    Rep Power
    4

    Default Re: i feel like a retard! Java noob!

    Did you have a specific question, or looking for tips, or something?

  3. #3
    javanab is offline Member
    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0

    Default Re: i feel like a retard! Java noob!

    Quote Originally Posted by Toll View Post
    Did you have a specific question, or looking for tips, or something?
    was curious , on a elegant way to write the program with the same output.

  4. #4
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    392
    Rep Power
    4

    Default Re: i feel like a retard! Java noob!

    Hmm. I won't give you any code, but I see two other approaches.

    1) Have two strings: One with enough 0s to match the length of the side, and one with the same amount of spaces. Then write "0"+border+"0" before a for-loop, "0"+spaces+"0" in a for-loop, and then "0"+border+"0" again after the for-loop. Voila, a nice square.

    2) Use a for-loop within another for-loop. The first for-loop would represent the Y and the second the X. If the values of X and Y say it's along the border, print a "0". Otherwise print a space.

    I'm sure there are other approaches as well, but those two were the ones that popped into my head.

    EDIT: That is, of course, if I understood your intention correctly. For instance, if a user enters 4, it should output:
    Java Code:
    0000
    0  0
    0  0
    0000

  5. #5
    doWhile is online now Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: i feel like a retard! Java noob!


  6. #6
    javanab is offline Member
    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0

    Default Re: i feel like a retard! Java noob!

    Quote Originally Posted by doWhile View Post
    slick mod -.-, was looking for a java forum but found this one is much more active!

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: i feel like a retard! Java noob!

    there's nothing wrong with cross-posting, but please notify all forums if you do that out of consideration so that we don't waste time duplicating effort that has been performed elsewhere.

Similar Threads

  1. Help with GUI - Java NOOB :(
    By bdelarosa7 in forum New To Java
    Replies: 3
    Last Post: 11-22-2011, 09:54 PM
  2. Java Look and Feel
    By RichersooN in forum AWT / Swing
    Replies: 3
    Last Post: 01-25-2011, 08:52 PM
  3. Help im a noob.. a super noob on java..
    By critdevil in forum New To Java
    Replies: 12
    Last Post: 03-07-2009, 03:17 AM
  4. Hello, Java Noob
    By furry in forum Introductions
    Replies: 0
    Last Post: 10-07-2008, 07:39 PM
  5. Ah! Help a Java Noob
    By Snejana in forum New To Java
    Replies: 4
    Last Post: 01-24-2008, 03:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •