Re: Moar Questions! (By Sea)
Firstly let me introduce myself:
http://www.javaprogrammingforums.com...html#post40433
Now that its out of the way (:D) let me start:
I have seen a GOOD programmer do his Ludum Dare challenge in java. It inspired me to start writing in java, and as i love coding and programming (many things with actionscript 2) i thought it would be a good start to learn java (naturally... :))
I will post in this thread with continual questions :P
Thanks and much appreciated ^^
Re: Frames - Using and creating (+another question)
Quote:
public static void main(String[] args)
is a method called 'main'. It has a 'void' return type which means it doesn't return anything, so can't be used on the RHS (Right Hand Side) of assignments - you can't say "x = main(...)". It is 'static' meaning that you do not have to instantiate (create a new object) its class in order to use it. If it was declared in a class called "MyApp", you would invoke it as "MyApp.main(...)". While you can invoke a static method on an instance of a class, it is regarded as bad practice. It's 'public' so that any code from anywhere which can load your class can invoke main(...).
The method 'signature' above is the specific method the JVM looks for when you start your Java code with "java MyApp". The JVM loads, then loads your MyApp class, then it invokes MyApp.main(...). The 'String[]' is the type of the only argument to main - args - an 'array of Strings'. If you start your JVM like this: "java MyApp apple orange 42" then args willl be an array of length 3. args[0] will be "apple", args[1] will be "orange" and args[2] will be "42". Note that "42" is a String of two characters, not a number.
Quote:
What is the double xx, double yy, double zz. (examples)
One question at a time!
Primitive Data Types (The Java™ Tutorials > Learning the Java Language > Language Basics)
Re: Frames - Using and creating (+another question)
You might not like this, but the best advice I can give you is to start slower. Work your way through the basic tutorials, which will explain methods and classes and Objects and data types, and only when you really understand that stuff, then think about working on the GUI.
If I were you, I'd start here: The Java™ Tutorials
Re: Frames - Using and creating (+another question)
Olla guys! I have returned with MOAR question(s):
My question is, what is the difference between printf and println (i know that f stands for formatted)
SOLVERED: Print Ln is print line :P
Re: Frames - Using and creating (+another question)
What did the API tell you?
Recommended reading: PrintStream (Java Platform SE 6)
Re: Frames - Using and creating (+another question)
Thank you sir :P
I have another question (you like how i keep my questions in one thread?):
I have a program that tells the person to type in a number, this number with another one will be summed and printed to the user.
I would like to restrict the person such as when they type a letter it would say "Please type a valid number!"
I used the switch(number) and i want case(1-999). What i really want is "Type a number from #1 TO #999" and if they do not i would do
Code :
default:
System.out.println("Please input a valid number!");
break;
which prints "Enter a valid number!"
How do i do this 'To' ?
Re: Frames - Using and creating (+another question)
You will need a loop.
Code java:
loop {
prompt user for input;
if input is valid {
break loop
}
}
Re: Frames - Using and creating (+another question)
Hmm.. ok ill try that when i get to my learning stage with loops :P cheers Junky! ^^
Re: Frames - Using and creating (+another question)
@Junky: Thanks, but i did it as such:
Code :
if(fnum>=1 && fnum<= 999){
And it works :P
I have another question, if i want to call back on this method because the user has inputed an invalid argument, how do i do that? because it was hard to call my main class which calls my secondary, and i cant use my main to test the secondary's method.
This is the general code:
Code :
if(fnum>=1 && fnum<= 999){
System.out.println("And a second number please, same restrictions");
snum = name.nextDouble();
Math.round(snum);
if(snum>=1 && snum<=999){
tot = snum + fnum;
prod = snum*fnum;
System.out.print("Thanks " + sea + ". I will now take both your numbers, " + fnum);
System.out.println(" and " + snum + ", and add them. ");
System.out.println(tot + " is the sum of both numbers; " + prod + " is the product of the two :D");
System.out.println("Thank you," + sea + ", for using SillyDodo(tm) Media! Enjoy the rest of your day!");
System.out.println("To restart type in 'Restart' without the inverted commas!");
rest = restart.nextLine();
} else {
System.out.println("Game Over... mate!");
}
} else {
System.out.println("Game Over... mate!");
}
and i want to restart when the user types 'Restart'.
Another question:
How do I check if the inputted argument is a number or not?
For
Code :
System.out.println("And a second number please, same restrictions");
snum = name.nextDouble();
Math.round(snum);
if(snum>=1 && snum<=999){
I want to check if snum is also a number or not... do i do
Code :
if(snum != double){
System.out.println("You need a valid number! Letters are not numbers!");
Thank you :P I appreciate your support.
p.s. is it annoying that im asking so many questions?
Re: Frames - Using and creating (+another question)
Same advice as above. Use a loop.
Re: Frames - Using and creating (+another question)
How do i check if they entered a string or a double/integer ?