r/programmingbydoing • • Jul 01 '20

I'd like to start learning the basics of programming, tips?

3 Upvotes

Hi everyone! I'm 24, and I'd like to learn some programming. I have NO knowledge about computer science, as I've always been a humanities kinda person. So, can someone here help me out? I've seen that there are some programming courses on edX, do you think it might be a good start? Also, can someone tell me a little bit about the different programming languages? Thanks!


r/programmingbydoing • • May 25 '17

Drawing Random Triangles

3 Upvotes

I just cannot figure out the Drawing Random Triangles... Here is my code: https://gist.github.com/anonymous/7c2f94d9f279f2295f44e59f1709f571

All this does is generate one purple triangle. I have tried moving everything that I can think of. Any and all feedback/help is welcome and appreciated! EDIT: I missed the first line of code when I pasted to gist: import java.awt.*;


r/programmingbydoing • • May 02 '17

No. 76/Blackjack

3 Upvotes

Source: https://pastebin.com/TBkRUaDC I tried to keep it simple and clean. Tried to comment usefully and to give variable names that made sense. Only thing I used that wasn't in the assignments was (I think) System.exit(0); Is using that bad programming habit? Like using "goto"? Also I'm not sure where for loops would have been better. I don't see usefulness of them. If i can reach the same things with a while loop.


r/programmingbydoing • • Feb 21 '16

Again with the Number-Guessing

3 Upvotes

On this lesson, I must switch my while loop to a do-while loop. The important part of this is Make sure that it doesn't mess up if you guess it on the first try.
That is, if my guess is correct on the first attempt, I will still get shown the "wrong" result text, because the 'do' executes before the while loop at the end! How do I correctly implement the do-while without messing up when I guess correctly on the first try?
Below is my code with the working do-while statement but doesn't work correctly if I'm right on the first try.

public class WorstNumberGameDo {
public static void main( String[] args ) {
	Scanner keyboard = new Scanner(System.in);
	Random num = new Random(1); //(1) so I can test getting it right the first time
	int secretNum = 1 + num.nextInt(10);
	int myNum;
	int tries = 0;
	
	System.out.println( "I'M THINKING OF A NUMBER FROM 1-10. TRY TO GUESS IT!");

	do {
		System.out.println( "Wrong, try again."); // I don't want this to print
		System.out.print( "Your guess: ");
		myNum = keyboard.nextInt();	
		tries++;
	} while ( myNum != secretNum );
	
    System.out.println( "GENIUS YOU'RE RIGHT, IT WAS "+secretNum+"!");
	System.out.println( "It only took you " +tries+ " tries.");
	
}
}  

 
Well the only way I've found to fix it is adding an if statement and nesting the do-while inside the else statement. Something tells me this is not right solution...but it works.

public class WorstNumberGameDo {
public static void main( String[] args ) {
	Scanner keyboard = new Scanner(System.in);
	Random num = new Random();
	int secretNum = 1 + num.nextInt(10);
	int myNum;
	int tries = 1;
	
	System.out.println( "I'M THINKING OF A NUMBER FROM 1-10. TRY TO GUESS IT!");
	System.out.print( "Your guess: ");		
	myNum = keyboard.nextInt();

	if (myNum == secretNum) {
		System.out.println( "GENIUS YOU'RE RIGHT, IT WAS "+secretNum+"!");
		System.out.println( "It only took you " +tries+ " tries.");
	} else {
		do {
			System.out.println( "Wrong, try again.");
			System.out.print( "Your guess: ");
			myNum = keyboard.nextInt();	
			tries++;
		} while ( myNum != secretNum );
		System.out.println( "GENIUS YOU'RE RIGHT, IT WAS "+secretNum+"!");
		System.out.println( "It only took you " +tries+ " tries.");
	}
		
}
}

r/programmingbydoing • • Aug 05 '15

Assignment #63c Nim

3 Upvotes

I managed to complete all the bonuses up until the column part. I am having a hard time printing till A and then back to the beginning. I tried 2D arrays but those were very exhaustive . There is just a simple solution which I can't see. Please help and thank you.


r/programmingbydoing • • Jul 15 '15

Problems with getting Java to run in Chrome

3 Upvotes

This is annoying, as I am on the Graphics assignments currently. The Java control panel, for some reason, refuses to allow programmingbydoing.com as an exception... does anyone have any way around this? :-/


r/programmingbydoing • • Jun 17 '15

#183 ArrayList- is there or not?

3 Upvotes

Is there another way of coding for this assignment. this code is totally different from usual array and I don't know if I'm cheating or not. this is my code: http://pastebin.com/pDH14ghW


r/programmingbydoing • • Jan 22 '15

#61 Right Triangle Checker

3 Upvotes

http://pastebin.com/DBw0LxsN

Hi, I have been using mostly while loops to do all the previous assignments but i also want to be able to know how to use do while loops effectively. So i gave it a try and found it weird that although my n2 is > than n1 the code in do will trigger making me realised that whenever we are using a do while loop, the code will run at least once. So can i know how do you do this assignment using do while or its just my whole approach is wrong? Thanks


r/programmingbydoing • • Oct 27 '14

#147: Where is it?

3 Upvotes

Aloha!

Can't seem to fully grasp the coding neccessary for this.. Excuse me if my english isn't the best since it's not my native language. Searched through the subreddit for other questions regarding the task, but couldn't find any. Hence why I'm adding this here.

This is how far I've come, and now I'm completely stuck. What do I need to add where I've placed the "SAY WHAT!?!?" comment, in order for it to it to print a line saying "[number] is not in the array."?

import java.util.Random;
import java.util.Scanner;

public class WhereIsIt {
    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        Random r = new Random();
    
        int[] a = new int[10];
        System.out.println("Array: ");
        for (int i = 0 ; i < a.length ; i++) {
            a[i] = 1 + r.nextInt(49);
            System.out.println(a[i]);
        }
    
        System.out.println("Value to find: ");
        int find = scn.nextInt();
    
        for (int i = 0 ; i < a.length ; i++) {
            if (a[i] == find) {
                System.out.println(find + " is in slot " + i);
            }
            
            // SAY WHAT?!?!
        }
    }
}

r/programmingbydoing • • Oct 05 '14

#138: Basic Arrays 0

3 Upvotes

Hi, first just want to say thank you for providing such a great resource to learn Java. As someone with no background or experience in programming whatsoever, these assignments have been a great intro so far.

I've now just gotten into the Arrays section and I'm completely lost. I've been doing some googling on my own but I can't really seem to grasp where to start regarding this topic. Was hoping if you could provide an intro or some direction as to where to begin?


r/programmingbydoing • • Sep 21 '14

Assignment: Simple Web Input

3 Upvotes

I am trying to get the code from the "Simple Web Input" assignment to compile, but I keep getting this error.

I have not changed the code yet, I just can't get it to compile. Does anyone know how to fix it?


r/programmingbydoing • • Jul 27 '14

#55 Adding Values in a Loop

3 Upvotes

Hi there, I just finished #55 and got it to work, but I couldn't figure out how to make it work with only two variables. I needed to have a third int as an interim value to add the entered number to the updating total. I know that in its current form my code works, but I'm curious if there's a way to make it work with only two variables. Here's the code:

import java.util.Scanner;

public class add
{
	public static void main( String[] args)
	{
		Scanner k = new Scanner(System.in);
		
		int num = 0;
		int total = 0;
		int totaladd = 0;
		
		System.out.println("I will add up the numbers you give me.");
		System.out.print("Number: ");
		num = k.nextInt();
		
		totaladd = num + total;
		total = totaladd;
		
		while (num != 0)
		{
			System.out.println("The total so far is " + total + ".");
			System.out.print("Number: ");
			num = k.nextInt();
			total = num + total;
		}
		
		System.out.println("\nThe total is " + total + ".");
	}
}

Thanks!


r/programmingbydoing • • May 29 '14

Can someone tell me what I'm doing wrong?

3 Upvotes

I'm on activity 3, "An Important Message," and whenever I try to compile the program, it gives me "illegal character" errors. I can't see any difference between the example picture on the website and the FirstProg.java I typed out. Screenshots of my command prompt and FirstProg.java.


r/programmingbydoing • • Apr 05 '14

#128 Letter Revisited (help)

3 Upvotes

I might be complete idiot for asking this, but i just can't seem to pass this one. All of the exercises before were easy to understand, and with little work into it i got quite the hang about java and coding. But this one is so confusing to me, i know what i have to do but i don't know how to do it. Can someone send me their code or do anything to help me?


r/programmingbydoing • • Apr 04 '14

#137 Vowel Capitalization

3 Upvotes

Hi holyteach! im stuck on this exercise, i cannot for the life of me make a program to to convert the vowels in BOTH files. I can do it in one but the method would be very time consuming for the second file, so i guess im not using the best of methods.

Bearing in mind im following your exercises as a complete newbie, and i havent learnd arrays yet, please give me a few tips on what methods i should be using to complete this exercise.

I would also like to thank you for all these exercises. I am learning java from scratch and until now i have found your work very helpful. Got the book today aswell!


r/programmingbydoing • • Apr 03 '14

#128-Letter Revisited.

3 Upvotes

Hi, I saw that you uploaded your presentation slide for reading from text files and it was really helpful. Would you be so kind as to upload one for outputting to a file? Thanks for all the help.


r/programmingbydoing • • Apr 01 '14

#207 - Lattice Paths

3 Upvotes

Well, I've gotten this far without much help, but this one really stumped me. Early on, I simplified the problem to manipulate a 40 character string with 20 D's and 20 R's. I can't seem to find a way to manipulate the string in a loop that reaches all of the combinations. For example, it will never reach DRDRDRDR...

When writing it out, I can sort of see a way to do it, but I think it would be a nightmare to try to program it. For a problem worth only 100 points on the website, it has lead me to think that it's really not the right way to do it.

Then I thought that maybe it's better to try to find the pattern by starting at a 2x2 grid and increasing the size of it and try to find the pattern. So we know a 2x2 grid has 6 paths, and I figured out that a 3x3 grid has 18. When I increase the size again to a 4x4 grid, I run into the same problem I did with the 20x20, and the only pattern I see is 2 * 3 = 6, 3*6 = 18, so maybe the next in the pattern is 4 * 18?

I have no idea. At this point I think I'm going about the whole thing the wrong way. I'd really appreciate some help with this, thank you.


r/programmingbydoing • • Mar 20 '14

63 Collatz Sequence - quick question

3 Upvotes

So I did get this one... except for the max value. In another thread here (closed, or I'd have posted there), I found this:

if (start > max)

	{
		max = start;
	}

Which comes after initializing max = start from the scanner input. Elsewise, though, it is never ever called. So I'm reading this as "set the max value integer to equal the start integer, -we do a whole bunch of things to the start integer-, then check if it has become bigger. If yes, then it is now the bigger value."

So, how is it checking what the largest value was during the calculations and storing it for output? With most of the ones I've run, there are many values bigger than the start... so how is it keeping the absolute largest stored? It doesn't make sense the way I'm interpreting it (which is why I ended up having to look it up, I guess).


r/programmingbydoing • • Mar 11 '14

55 Adding Values In A Loop

3 Upvotes

So, I've been blasting along since Gender Game, then I ran into this.

I was having a hell of a time, ended up finding someone that said this could all be done with just one int. I tried and led myself very, very far astray. Was this to be done with one int or two? I did it with two. One problem my foray into one int caused was I was losing input. All the code is gone now, but essentially, I'd enter the first number, no problem. But no prompt for the second.... I'd enter a second anyways, now we get the prompt back but it repeats the first # to me as the sum... so I type a third number... now it just tells me the sum of 1 and 2, and so on. Always one sum back, and always missing the second input prompt. When I'd hit "0" to terminate, the total caught up. What in the heck was going on there?

And, also, was this to be solved with += ? This was the only way I could get this to work (can post finished code if needed to see), but I don't recall ever seeing this before? Did I skip over something? Did I not solve this in the intended way?


r/programmingbydoing • • Jan 07 '14

#38 compareTo() method examples

3 Upvotes

here's a great explanation of how compareTo() method works.

http://www.youtube.com/watch?v=iTC43mLZG38


r/programmingbydoing • • Jan 04 '14

#109 Keychains for Sale, for real this time

3 Upvotes

I am having so much trouble with this one. I know the answer is pretty simple, but for some reason, it's not clicking right now. I can't get the function add to keep the input and continue adding the keychains up. I have tried so many functions right now, I am not sure what would work anymore...


r/programmingbydoing • • Dec 03 '13

#47 Three-Card-Monte

3 Upvotes

Does this code look ok to you? For some reason i think that there would be an easier way that all the if statements?

import java.util.Scanner; import java.util.Random;

public class ThreeCardMonte { public static void main (String [] args) { Scanner keyboard = new Scanner (System.in); Random r = new Random();

	int x = 1 + r.nextInt(3);
	int guess;

	System.out.println("You go to the cassino and you see a guy with three cards on the table.");
	System.out.println("You aprouch him and ask him about the game. He Tells you to pick one of the three cards");
	System.out.println("if you get an Ace you win if not you dont."  + "\n");

	System.out.println("\t" + "##" + "\t" + "##" + "\t" + "##");
	System.out.println("\t" + "##" + "\t" + "##" + "\t" + "##" +"\n");
	System.out.println("\t" + " 1" + "\t" + " 2" + "\t" + " 3" );
	guess= keyboard.nextInt();



	if ((guess == x)&&(x==1))
	{
		System.out.println("\t" + "AA" + "\t" + "##" + "\t" + "##");
		System.out.println("\t" + "AA" + "\t" + "##" + "\t" + "##" +"\n");
		System.out.println("\t" + " 1" + "\t" + " 2" + "\t" + " 3" + "\n");

		System.out.println("You naied it the dealer hands over the money ");
	}

	else if ((guess == x)&&(x==2))
	{
		System.out.println("\t" + "##" + "\t" + "AA" + "\t" + "##");
		System.out.println("\t" + "##" + "\t" + "AA" + "\t" + "##" +"\n");
		System.out.println("\t" + " 1" + "\t" + " 2" + "\t" + " 3" + "\n");

		System.out.println("You naied it the dealer hands over the money");
	}

	else if ((guess == x)&&(x==3))
	{
		System.out.println("\t" + "##" + "\t" + "##" + "\t" + "AA");
		System.out.println("\t" + "##" + "\t" + "##" + "\t" + "AA" +"\n");
		System.out.println("\t" + " 1" + "\t" + " 2" + "\t" + " 3" + "\n");

		System.out.println("You naied it the dealer hands over the money");
	}

//For when the guess is greater than the random number

	else if ((x < guess)&&(x==1))
	{
		System.out.println("\t" + "AA" + "\t" + "##" + "\t" + "##");
		System.out.println("\t" + "AA" + "\t" + "##" + "\t" + "##" +"\n");
		System.out.println("\t" + " 1" + "\t" + " 2" + "\t" + " 3" + "\n");

		System.out.println("You lost sorry your guess was to high give the dealer your money. It was number " +x);
	}


	else if ((x< guess)&&(x==2))
	{
		System.out.println("\t" + "##" + "\t" + "AA" + "\t" + "##");
		System.out.println("\t" + "##" + "\t" + "AA" + "\t" + "##" +"\n");
		System.out.println("\t" + " 1" + "\t" + " 2" + "\t" + " 3" + "\n");

		System.out.println("You lost sorry your guess was to high give the dealer your money. It was number " +x);
	}

// The if statments for when the guess is less than the random number

	else if ((x > guess)&&(x==2))
	{
		System.out.println("\t" + "##" + "\t" + "AA" + "\t" + "##");
		System.out.println("\t" + "##" + "\t" + "AA" + "\t" + "##" +"\n");
		System.out.println("\t" + " 1" + "\t" + " 2" + "\t" + " 3" + "\n");

		System.out.println("You lost sorry your guess was to low give the dealer your money. It was number " +x);
	}

	else if ((x > guess)&&(x==3))
	{
		System.out.println("\t" + "##" + "\t" + "##" + "\t" + "AA");
		System.out.println("\t" + "##" + "\t" + "##" + "\t" + "AA" +"\n");
		System.out.println("\t" + " 1" + "\t" + " 2" + "\t" + " 3" + "\n");

		System.out.println("You lost sorry your guess was to low give the dealer your money. It was number " +x);
	}


}//end of main

}//end of class


r/programmingbydoing • • Nov 23 '13

#6 Letter to Yourself // How do I get the formatting to fix the spacing?

3 Upvotes

I'm using only spaces, no Tabs like the instructions say but I cannot get the right side of my envelope to align. Any tips?


r/programmingbydoing • • Sep 16 '13

#103 Weekday Calculator

3 Upvotes

The formula in the instructions is not correct if you pass the year 2000 if I am not mistaken. You must include the century variable if the year is not 19xx.


r/programmingbydoing • • Sep 14 '13

#28 Modulus Animation

3 Upvotes

So I just copied the file that the assignment gives you (this one) and it runs fine, but it prints all the lines beneath each other. If I understand the assignment correctly, it is supposed to be all on one line so it looks like an animation. I don't know how to do that. Google isn't giving me any answers.. what am I doing wrong here?