Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Smarmy Coworker
May 10, 2008

by XyloJW
something I didn't consider. Also probably correct. I'll throw in some checks and see if it starts to work.

Adbot
ADBOT LOVES YOU

greenchair
Jan 30, 2008
So Ive made a program in eclipse that I kind of like, and I'd like to be able to run it without opening the project in eclipse and then compiling and running it from there. How do I make it into an actual program that I just double click on and then it opens and runs?

hooah
Feb 6, 2006
WTF?

greenchair posted:

So Ive made a program in eclipse that I kind of like, and I'd like to be able to run it without opening the project in eclipse and then compiling and running it from there. How do I make it into an actual program that I just double click on and then it opens and runs?

I believe you can export it as a jar, which should be runnable on its own. However, the only Java stuff I've done is the tutorial videos hosted on Sourceforge that are in the OP, so take that as you will.

Volguus
Mar 3, 2009

greenchair posted:

So Ive made a program in eclipse that I kind of like, and I'd like to be able to run it without opening the project in eclipse and then compiling and running it from there. How do I make it into an actual program that I just double click on and then it opens and runs?

There are a number of ways to do this:
1) Make a runnable jar : http://www.mkyong.com/java/how-to-make-an-executable-jar-file/
2) Let Ant make a runnable jar for you: http://stackoverflow.com/questions/9874550/how-to-create-a-bundled-runnable-jar-using-ant
3) Let maven make a runnable jar: http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven

It doesn't matter which one you choose for an one-off project. For a maintainable and an easy to share (between developers) maven is probably your best bet. Or Ant with ivy. Any of the 3 methods will provide you with the desired end result. The difference is with maintenance.

Doctor w-rw-rw-
Jun 24, 2008
Pretty sure Eclipse can also export .jar files if you specify a main class to execute?

Safe and Secure!
Jun 14, 2008

OFFICIAL SA THREAD RUINER
SPRING 2013
So what is "modern" Java web development like? It's all enterprise stuff, right? And JSP is considered ancient, as is the slightly more recent JSF? I guess Spring is where modern, enterprise Java development is at, but isn't that just a dependency injection framework with a lovely MVC module available if you hate yourself? Never used Spring, that's just the impression I got from when I was looking for a Java web framework a while ago before I said "gently caress it" and decided I'd rather have some fun with Scala.

Volguus
Mar 3, 2009

Safe and Secure! posted:

So what is "modern" Java web development like? It's all enterprise stuff, right? And JSP is considered ancient, as is the slightly more recent JSF? I guess Spring is where modern, enterprise Java development is at, but isn't that just a dependency injection framework with a lovely MVC module available if you hate yourself? Never used Spring, that's just the impression I got from when I was looking for a Java web framework a while ago before I said "gently caress it" and decided I'd rather have some fun with Scala.

The spring MVC module is anything but lovely, but to each his own. JEE has come a long way since 2004. Now you have specifications like JSR 311 & JSR 339 with libraries like Jersey (the reference implementation) or RESTEasy.
If you like Scala though, there's nothing wrong with that either, though im my personal opinion, the Scala web frameworks are either:
- less feature-full than spring (for example). seem quite a bit immature (scalatra)
- different for the sake of being different (Play2).

Hipsters though, use things like nodejs for web development, with stuff like mongodb on the backend. Nothing wrong with that either if that's what you like.

greenchair
Jan 30, 2008

hooah posted:

I believe you can export it as a jar, which should be runnable on its own.

Thanks! For something that I think would be pretty common it was surprisingly unintuitive (to me at least). For any others out there wondering exactly how to do it:
1. Make sure you have the correct workspace open in eclipse
2. File -> Export. This brings up a menu that says "Select Export Destination"
3. Click on the Java Folder icon so that it is showing its contents
4. Click on "Runnable Jar file"
5. Click next, this brings up a screen "Runnable Jar File Specification"
6. In the first drop down menu find the name of the file that contains the "main" method. The project name is on the right
7. For "Export Destination" click on browse and find the folder you want it in, name it
8. Don't really know what the library handling stuff is I just picked the first option.
9. Don't know what ant is. I left it unchecked.
10. Click on Finish. It's done!

This is probably super obvious to most out there, but it took me a while to figure out, so maybe someone else will find it useful.

Posting Principle
Dec 10, 2011

by Ralp

Safe and Secure! posted:

So what is "modern" Java web development like? It's all enterprise stuff, right? And JSP is considered ancient, as is the slightly more recent JSF? I guess Spring is where modern, enterprise Java development is at, but isn't that just a dependency injection framework with a lovely MVC module available if you hate yourself? Never used Spring, that's just the impression I got from when I was looking for a Java web framework a while ago before I said "gently caress it" and decided I'd rather have some fun with Scala.

I've actually been doing Java web development recently, and it's been pretty nice. For REST you have JAX-RS, which is surprisingly sane, and forms the core of Dropwizard, which is a library for easily building web services. I haven't used Spring MVC, but Spring provides other things like data access and AOP. As far as HTML templating goes, I've been using jade4j, which is just a port of jade to Java. All of this either runs in web container like Tomcat, or as a standalone JAR, so you don't have to muck around with app servers. Overall it's been good, and I haven't seen a lot of the cruft or FactoryFactoryImpls that people associate Java with.

Doctor w-rw-rw-
Jun 24, 2008

Safe and Secure! posted:

So what is "modern" Java web development like? It's all enterprise stuff, right? And JSP is considered ancient, as is the slightly more recent JSF? I guess Spring is where modern, enterprise Java development is at, but isn't that just a dependency injection framework with a lovely MVC module available if you hate yourself? Never used Spring, that's just the impression I got from when I was looking for a Java web framework a while ago before I said "gently caress it" and decided I'd rather have some fun with Scala.

Use Guice for DI instead. Guava for some neat data structures, and Dropwisard for running web APIs (or Jersey, which Dropwizard wraps, if you would prefer to deploy to Tomcat/Jetty/etc). IMO steer clear of Spring.

Sab669
Sep 24, 2009

Any recommendations on some absolute bare-bones First Programming Language books for Java? My roommate is going into his second semester of Comp Sci and he's really struggling. Decided to wait until the last week of vacation to buy a book and try to get back into it before the next semester starts :v:

Java, A Beginner's Guide seems to have good reviews.

Volguus
Mar 3, 2009

Doctor w-rw-rw- posted:

IMO steer clear of Spring.

This is a bad advice. Spring is extremely useful in a large number of applications. Is a huge framework, yes, but it can help more than it can hurt if you use it wisely. Check out the number of projects available: http://spring.io/projects

Doctor w-rw-rw-
Jun 24, 2008

rhag posted:

This is a bad advice. Spring is extremely useful in a large number of applications. Is a huge framework, yes, but it can help more than it can hurt if you use it wisely. Check out the number of projects available: http://spring.io/projects
Well, it *is* just my opinion. I just never reached the point where adding in a particular component ended up being a net value-add.

Just because it has a large number of projects available doesn't necessarily mean they're any good. Can you explain some of its advantages?

Volguus
Mar 3, 2009

Doctor w-rw-rw- posted:

Well, it *is* just my opinion. I just never reached the point where adding in a particular component ended up being a net value-add.

Just because it has a large number of projects available doesn't necessarily mean they're any good. Can you explain some of its advantages?

I would recommend then to check some of them out. The introductory page should tell you about what they do.

But, in one sentence, let me go through some of them that i have used:

- Spring Data JPA - You get full CRUD operations on an entity writing one single line of code: public interface MyRepository extends JpaRepository<MyEntity,Integer>{} . Need more? You can write special queries, or do special poo poo
- Spring web flow - a fantastically easy to write web flow api. really. it rocks (web flow, such as wizards).
- Spring AOP - great support for aspects. cannot be easier (Few annotations, and you're golden).
- Spring MVC - you can write REST applications, or use JSPs or any other view easily (xslt,freemaker,velocity). Writing controllers is trivial as well, just annotate your class correctly and you have any path you want.
- Spring Integration - Written to support the Enterprise Integration Patterns. I used it to very easily get data from RSS feeds, ftp's or http sources. it made things a lot easier.
- Edit: Spring Security (how could i forget that): - please find me an easier way to secure an application, while getting everything right and having easy way to write your own stuff should you need to. It comes with OAuth, kerberos, LDAP and AD integration, where you need to write very little if any code. Plus of course, the old username/password auth. Supports ACLs and path security.

Now, where is spring not suited?

Spring is big and can be heavy. I havent used yet the 4.x release, but with 3.x ... i wouldnt use spring in a desktop application. For light CDI, google-guice is great. But you cannot deny what spring brings to the table. Shitload of things that you don't have to write, that others have written for you probably better than you would be able to.

Another project they have in there is called Grails. It's a huge and very heavy framework, using the Groovy language, but which can help you write a complex and full featured web app in days. Its perfect for when the boss wants you to be done yesterday, and still have an easy to maintain web app. However, grails is heavy, i wouldn't put it on an internet-facing server. But for internal web apps, i don't think you can find a faster to develop in framework.

Volguus fucked around with this message at 05:40 on Jan 13, 2014

FateFree
Nov 14, 2003

Sab669 posted:

Any recommendations on some absolute bare-bones First Programming Language books for Java? My roommate is going into his second semester of Comp Sci and he's really struggling. Decided to wait until the last week of vacation to buy a book and try to get back into it before the next semester starts :v:

Java, A Beginner's Guide seems to have good reviews.

I like the Head First java series for complete beginners. It has pictures.

Gravity Pike
Feb 8, 2009

I find this discussion incredibly bland and disinteresting.

Sab669 posted:

Any recommendations on some absolute bare-bones First Programming Language books for Java? My roommate is going into his second semester of Comp Sci and he's really struggling. Decided to wait until the last week of vacation to buy a book and try to get back into it before the next semester starts :v:

Java, A Beginner's Guide seems to have good reviews.

Honestly, I think the Oracle turorials are pretty decent. (Scroll down to "Trails Covering the Basics".) Comp Sci II doesn't cover anything more complicated than, like, Generic Collections, right? It's been forever.

Sab669
Sep 24, 2009

Gravity Pike posted:

Comp Sci II doesn't cover anything more complicated than, like, Generic Collections, right? It's been forever.


His first semester class was actually pretty weird. They covered basic data types, then jumped into objects and interfaces then flow control and loops. They did a bit with ArrayLists as well, never having even talked about just basic arrays.

By the end of the semester he barely comprehended the concept of 'returning' a value from a method, constructors, or creation of variables for things other than basic data types. I don't know if his professor sucked, or it was a lack of sufficient labs to give him practice or what.

tohveli
Nov 25, 2007

♪ オー マリア

Safe and Secure! posted:

So what is "modern" Java web development like?

I'm here to ask the same question, but mostly about the different libraries to use for views.
Coming from .NET, which has had a pretty good template engine for some while with strong typed models and simple, clear syntax, I'm hoping there is something similar for Java. I don't mean exact same syntax, but something that is proven to work well for projects with big teams, and is not an HTML-only library with hipster endorsed inflexible syntax. Maybe plain JSP is good?

Posting Principle
Dec 10, 2011

by Ralp
Have you tried Thymeleaf?

Volguus
Mar 3, 2009

tohveli posted:

I'm here to ask the same question, but mostly about the different libraries to use for views.
Coming from .NET, which has had a pretty good template engine for some while with strong typed models and simple, clear syntax, I'm hoping there is something similar for Java. I don't mean exact same syntax, but something that is proven to work well for projects with big teams, and is not an HTML-only library with hipster endorsed inflexible syntax. Maybe plain JSP is good?

Looking for 10 seconds at Razor ... it's very much like JSP. Few things here and there that are different, but ... it's JSP. What JSP has and that apparently does not is the concept of tags (that is, you can do <c:foreach...> instead of @foreach, but you can also make your own tags that do whatever you want them to). Unless i completely misunderstood what @foreach is and does.

For templating (have master page with bodies,etc.) you can use sitemesh3 in java. JSF is fine as well, though the existing jsf engines/libraries do tend to be a bit on the heavy side with all that HTML that's generated. But that's just a personal opinion. If you wanna give jsf a try (for the heck of it) checkout http://www.icesoft.org/java/projects/ICEfaces/overview.jsf .

DholmbladRU
May 4, 2006
This seems pretty trivial but I cant figure it out. How do you keep carriage returns from being removed from bufferedreader?


code:
 InputStream content = (InputStream) connection.getInputStream();
		 BufferedReader in = new BufferedReader(new InputStreamReader(content));
		   String line="";
				   
		    while ((line =  in.readLine()) != null) {
		    	__result = __result+line;
		    }
Is this safe?

code:
__result = __result+line+System.getProperty("line.separator");

DholmbladRU fucked around with this message at 22:09 on Jan 14, 2014

HFX
Nov 29, 2004

DholmbladRU posted:

This seems pretty trivial but I cant figure it out. How do you keep carriage returns from being removed from bufferedreader?


code:
 InputStream content = (InputStream) connection.getInputStream();
		 BufferedReader in = new BufferedReader(new InputStreamReader(content));
		   String line="";
				   
		    while ((line =  in.readLine()) != null) {
		    	__result = __result+line;
		    }
Is this safe?

code:
__result = __result+line+System.getProperty("line.separator");
If you use that the line separator will be that of the host system and not necessarily that of the input stream. You might want to use the read function instead.

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.

DholmbladRU posted:

This seems pretty trivial but I cant figure it out. How do you keep carriage returns from being removed from bufferedreader?

http://docs.oracle.com/javase/7/docs/api/java/io/BufferedReader.html

I would say look into the read() method instead, why use readLine if you don't want it stripped by lines? Don't force a square peg into a round hole. Always go to the java docs first! :)

Java code:
char[] charArray = new char[100];
BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
int actualBuffered = buffer.read(charArray,0,100);

Gravity Pike
Feb 8, 2009

I find this discussion incredibly bland and disinteresting.

DholmbladRU posted:

This seems pretty trivial but I cant figure it out. How do you keep carriage returns from being removed from bufferedreader?


This is a perfect oppurtunity to use the Apache Commons IOUtils class:

Java code:
InputStream contentStream = (InputStream) connection.getInputStream();
String content = IOUtils.toString(contentStream);
This is not a problem that has never been solved before. No need to re-invent the wheel.


Fake Edit:

Also, if you're going to be looping through the file like that, you really ought use a StringBuilder instead of concatenating strings. Since a String is immutable, what that does is allocate memory for the first line, and write the first line's worth of characters to that memory. Then it allocates enough memory for the first two lines, and copies the first two lines worth of characters to that memory block. Then it allocates enough memory for the first three lines, and copies those three lines to memory... You end up writing something like (lines^2 * average-line-length) characters. If you use a StringBuilder, it saves a reference to each String, and only when you call toString does it allocate enough memory to hold everything put together.

Java code:
String line;
StringBuilder sb = new StringBuilder();
while ((line = reader.getLine()) != null) {
    sb.append(line);
    sb.append("\n"); // or whatever
}
String content = sb.toString();

Volguus
Mar 3, 2009

Gravity Pike posted:


Fake Edit:

Also, if you're going to be looping through the file like that, you really ought use a StringBuilder instead of concatenating strings. Since a String is immutable, what that does is allocate memory for the first line, and write the first line's worth of characters to that memory. Then it allocates enough memory for the first two lines, and copies the first two lines worth of characters to that memory block. Then it allocates enough memory for the first three lines, and copies those three lines to memory... You end up writing something like (lines^2 * average-line-length) characters. If you use a StringBuilder, it saves a reference to each String, and only when you call toString does it allocate enough memory to hold everything put together.

Java code:
String line;
StringBuilder sb = new StringBuilder();
while ((line = reader.getLine()) != null) {
    sb.append(line);
    sb.append("\n"); // or whatever
}
String content = sb.toString();

The java compiler (at least from Sun/Oracle) has been able to see these kind of patterns since jdk 1.4 or so. It generates code that is using the stringbuilder, no need to worry. Still, it is a good habit to have, to not concatenate strings just for the sake of it.

Gravity Pike
Feb 8, 2009

I find this discussion incredibly bland and disinteresting.

rhag posted:

The java compiler (at least from Sun/Oracle) has been able to see these kind of patterns since jdk 1.4 or so. It generates code that is using the stringbuilder, no need to worry. Still, it is a good habit to have, to not concatenate strings just for the sake of it.

Huh, that's neat. I knew the compiler could do that for things like
Java code:
String msg = "Why hello there, " + name + ", you're looking particularly " + adjective + " today!";
but I had no idea that it was going to figure out loops for me.

Chas McGill
Oct 29, 2010

loves Fat Philippe
I'm currently learning Java as part of a degree on the Open University in the UK. It's my first programming language (Sense, an OU variant of Scratch, doesn't count) and I'm coming late to it.

While I'm enjoying the course, there's a load of course-specific terminology (messages instead of methods etc) and I'm concerned that I'm learning Java in a weird way. Can anyone recommend a definitive beginners guide to Java and OOP programming that reflects how the language is used in real applications?

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.

Gravity Pike posted:

Huh, that's neat. I knew the compiler could do that for things like
Java code:
String msg = "Why hello there, " + name + ", you're looking particularly " + adjective + " today!";
but I had no idea that it was going to figure out loops for me.

In lots of cases its an optimization to simply unroll the loop, or at least unroll it a couple times, and the compiler does that constantly without you knowing. Some of your 'loops' don't even exist! :cheeky:

HFX
Nov 29, 2004

Zaphod42 posted:

In lots of cases its an optimization to simply unroll the loop, or at least unroll it a couple times, and the compiler does that constantly without you knowing. Some of your 'loops' don't even exist! :cheeky:

The best part is trying to convince people who setup the almighty automated rule scanners, that your code is more readable using concatenations and doesn't result in a performance hit. Then again its hard getting people to update any ideas.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
String.format is more readable IMO and is yet another way to do that

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Chas McGill posted:

I'm currently learning Java as part of a degree on the Open University in the UK. It's my first programming language (Sense, an OU variant of Scratch, doesn't count) and I'm coming late to it.

While I'm enjoying the course, there's a load of course-specific terminology (messages instead of methods etc) and I'm concerned that I'm learning Java in a weird way. Can anyone recommend a definitive beginners guide to Java and OOP programming that reflects how the language is used in real applications?

Have you seen the Oracle Java tutorials yet?

Chas McGill
Oct 29, 2010

loves Fat Philippe

Volmarias posted:

Have you seen the Oracle Java tutorials yet?
I've used them a bit when I've tried to explore concepts outside what the course has covered, but I'd prefer a paper book so I can study offline.

There's probably a way of turning them into PDFs or something, though.

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

Is it possible to declare an abstract method that takes a particular type of object as a parameter, and then in the subclass that implements that method, require another type of object that extends the original one? Something like this:

code:
public abstract class BaseClass {

	...

	/** Get this controller's current output value */
	public abstract <T extends BaseClass.Options> float getData(int socket, T options);

	public class Options{}
}
code:
public class SubClass extends BaseClass {

	...

	public float getData(int socket, SubClass.Options options) {
	    // bla bla
	}

	public class Options extends BaseClass.Options {
	    // things
	}
}
The abstract method is in the BaseClass to ensure all the subclasses implement it, but I want them each to require their own specific inner-class implementation of Options - but doing the above throws an error because the method signature doesn't match.

Is there a way to do what I'm trying to do, or should I just settle for using the same signature and type checking the options object when it's passed in? Sorry if this is full of stupid things, I'm kinda winging it here (especially with generics). Also this is on Android, in case there's any late-game Java magic that would otherwise help

deedee megadoodoo
Sep 28, 2000
Two roads diverged in a wood, and I, I took the one to Flavortown, and that has made all the difference.


derp... wrong thread...

Sedro
Dec 31, 2008

baka kaba posted:

Is it possible to declare an abstract method that takes a particular type of object as a parameter, and then in the subclass that implements that method, require another type of object that extends the original one? Something like this:
Your base class method accepts any BaseClass.Options. Your subclass only accepts SubClass.Options. So the subclass doesn't implement the base class signature in the case where T = BaseClass.Options or some other derivative.

What you can do is parameterize the type instead:
code:
public abstract class BaseClass<T extends BaseClass.Options> {

	...

	/** Get this controller's current output value */
	public abstract float getData(int socket, T options);

	public class Options{}
}
code:
public class SubClass extends BaseClass<SubClass.Options> {

	...

	public float getData(int socket, SubClass.Options options) {
	    // bla bla
	}

	public class Options extends BaseClass.Options {
	    // things
	}
}

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

Ahhh that's it, you're a star! Looks like I need to do a bit more reading to understand what's going on, but it's accepting it at least

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.

baka kaba posted:

Ahhh that's it, you're a star! Looks like I need to do a bit more reading to understand what's going on, but it's accepting it at least

Read on this track: http://docs.oracle.com/javase/tutorial/java/generics/inheritance.html

Drunkenboxer
Oct 3, 2007

eh?
Hey Guys, I am just starting out with Java and am writing a simple program that takes user input and calculates the exponent of a number. I am not allowed to use the math library.

My program works but for some reason the calculation of the exponents is way off, the numbers are all multiples of the base, but the exponents seem to shoot off.

I am not sure if this is a syntax error or whats going on!

code:
import java.util.Scanner;

public class Exponents 

{
	public static void main (String [] args)
	{ 

		int base = 1;
		int exp = 1;
		int calc = 1;
		int used = 1;
		
		
		Scanner input = new Scanner (System.in);
		System.out.print("Please enter number of exponents to calculate: ");
	        calc = input.nextInt();

	        for (used = 1;used <= calc;used++)
		    {
		    System.out.print("Enter the base: ");
		    base = input.nextInt();
		    System.out.print("Enter the exponent: ");
		    exp = input.nextInt();
		
		    if (exp != 0)
			{
			    int total = base;
			    for (int count = 0 ;count <= exp; count++)
			    {
				total *=  base;
			    }
			    System.out.println("Base " + base + " to the exponent of " + exp + " is " + total);
			     
			      		     
			}
		    else
			System.out.println("Base " + base + " raised to the power of " + exp + " is equal to 1 ");
		

		    }
		
	}


}
Cheers all, and thanks for any help!

Gravity Pike
Feb 8, 2009

I find this discussion incredibly bland and disinteresting.
There is a logical error, not a syntax error. (Syntax errors won't even compile in Java!) I have a feeling that you could catch your own error with a bit of testing. Tests should be simple. They should generally test one thing. Two is an easy number to work with in this case. Ask your program what 2^0, 2^1, 2^2, and 2^3 are. You're going to get wrong answers for some of them, but the pattern should make it pretty easy to work out what's happening.

Adbot
ADBOT LOVES YOU

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

^^^ :arghfist::choco:

Try running through your program yourself - pick a base and loop through the code, following your instructions. Try a few exponents starting at 0 and working up, and work out what they should be in advance.

When you have an exponent of 1, total should equal base. You set that, but then you hit your loop. Because you're checking if count is less than or equal to exp, and count starts at 0, you always enter the loop and multiply your total by the base at least twice.

You execute the code in the loop exp + 1 times, but you already set total to base1 before you got there.
So you're actually calculating base1 * baseexp+1, or baseexp+2.

You have to be careful with loops, and the code you always execute before or after them


e: edits for not even noticing what I was pointing out

baka kaba fucked around with this message at 01:38 on Jan 22, 2014

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply