Results 1 to 7 of 7
Thread: i feel like a retard! Java noob!
- 11-09-2012, 01:46 AM #1
Member
- Join Date
- Nov 2012
- Posts
- 3
- Rep Power
- 0
i feel like a retard! Java noob!
I´ve 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++; } } } }
- 11-09-2012, 01:49 AM #2
Re: i feel like a retard! Java noob!
Did you have a specific question, or looking for tips, or something?
- 11-09-2012, 01:51 AM #3
Member
- Join Date
- Nov 2012
- Posts
- 3
- Rep Power
- 0
- 11-09-2012, 01:57 AM #4
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
- 11-09-2012, 01:59 AM #5
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,605
- Rep Power
- 5
Re: i feel like a retard! Java noob!
Cross posted at i feel like a retard! Java noob
- 11-09-2012, 02:03 AM #6
Member
- Join Date
- Nov 2012
- Posts
- 3
- Rep Power
- 0
-
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
-
Help with GUI - Java NOOB :(
By bdelarosa7 in forum New To JavaReplies: 3Last Post: 11-22-2011, 09:54 PM -
Java Look and Feel
By RichersooN in forum AWT / SwingReplies: 3Last Post: 01-25-2011, 08:52 PM -
Help im a noob.. a super noob on java..
By critdevil in forum New To JavaReplies: 12Last Post: 03-07-2009, 03:17 AM -
Hello, Java Noob
By furry in forum IntroductionsReplies: 0Last Post: 10-07-2008, 07:39 PM -
Ah! Help a Java Noob
By Snejana in forum New To JavaReplies: 4Last Post: 01-24-2008, 03:52 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks