Page 2 of 5 FirstFirst 1234 ... LastLast
Results 21 to 40 of 89
Like Tree6Likes

Thread: Java

  1. #21
    romero4742 is offline Member
    Join Date
    Mar 2012
    Posts
    27
    Rep Power
    0

    Default Re: Java

    You should try buying a book. Reading + looking at code and practice problems can really help. Now you can take that and watch youtube videos on of my favorites is by this guy called "thenewboston" check it out. There are also many websites that let you practice the basics of java one that I sometimes use is CodingBat Programming is way more than memorizing it requires lots of practice.

  2. #22
    Join Date
    May 2012
    Posts
    28
    Rep Power
    0

    Default Re: Java

    Quote Originally Posted by EscSequenceAlpha View Post
    Josh I got an idea, I'm new to java myself but I'm learning. It might be intimidating to ask experts on every little thing... why dont you send me your questions and I'll take a look, I'll be your code buddy.

    I hear the experts laughing because they know I'm quite new and have asked very silly questions myself but I'll do the best I can (hey, how can looking at more code be a bad thing?) thats my attitude as of late
    i'd like that :)

  3. #23
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,797
    Rep Power
    19

    Default Re: Java

    You've been given the Oracle tutorials, which are a good place to start.
    What you really need to do is think of a simple project that you can then use as a learning exercise.
    Something which you can build on and add to as you go along, picking up new aspects of Java on the way.

    For example, when I started messing around with Android I used a Simon Says app as my target. Starting with a normal Java app that simply seleted numbers 1-4 and then the user repeated them back (not hard, as the numbers appeared on the console, but that wasn't the point). Then attach that code to an Android front end with 4 buttons. Then construct a high score mechanism, and persisitng it (ie saving to file or database). Then changing from buttons to graphics. Adding sound. By which point I had touched the main non-network aspects of an app.

    Having an app gives you something to tinker with as you read through the tutorials, and also something you can actually post here if you need a question answered. But it has to be an app that you can build on slowly, adding new techs as you go along.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #24
    chipp's Avatar
    chipp is offline Member
    Join Date
    Jul 2011
    Posts
    62
    Rep Power
    0

    Default Re: Java

    @poo: what we're trying to say is: there's more than plenty tutorials out there, but how people get more skill from the tutorials? because they learned it, they understand it... so, do you? if not, then, read the tutorial and understand it... :)

  5. #25
    Join Date
    May 2012
    Posts
    28
    Rep Power
    0

    Default Re: Java

    ok well, im watching "thenewboston" on youtube and i think im getting the hang of this a bit.

    can someone test me a little? i'll type a list of what i've learned so far:

    -System.out.print/println

    -Variables

    -Mathematics signs

    - int && double

    - or ||
    Last edited by JoshieWashiePoo; 05-18-2012 at 06:33 AM.

  6. #26
    chipp's Avatar
    chipp is offline Member
    Join Date
    Jul 2011
    Posts
    62
    Rep Power
    0

    Default Re: Java

    instead of asking for an example, why don't you try to make your own program and if you get stuck, ask a question and show us your full code? coz you asked for it, just make a simple calculation program...

  7. #27
    romero4742 is offline Member
    Join Date
    Mar 2012
    Posts
    27
    Rep Power
    0

    Arrow Re: Java

    make a small program out of this:
    you can make two variables of ints or doubles, create a variable that will store the result for operations done with the variables Ex.
    Java Code:
    int result = x * y;
    then you can use both println and print so you can see the difference... make at least 2 of each.
    show us the code at the end.

  8. #28
    Join Date
    May 2012
    Posts
    28
    Rep Power
    0

    Default Re: Java

    Quote Originally Posted by chipp View Post
    instead of asking for an example, why don't you try to make your own program and if you get stuck, ask a question and show us your full code? coz you asked for it, just make a simple calculation program...
    i hate that im having trouble with this :(

    right now i have variables set up for plus, minus, times, ect.. and they're assigned to numbers, but how do i check which one the user types in after the first number so it knows if they want to add subtract or times?

  9. #29
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,797
    Rep Power
    19

    Default Re: Java

    We could come up with lots of ways, but without seeing your code it's going to be hard to tell exactly where you;re stuck.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  10. #30
    Join Date
    May 2012
    Posts
    28
    Rep Power
    0

    Default Re: Java

    Quote Originally Posted by Tolls View Post
    We could come up with lots of ways, but without seeing your code it's going to be hard to tell exactly where you;re stuck.
    import java.util.Scanner;


    class Calc {
    public static void main(String args[]){
    Scanner Josh = new Scanner(System.in);
    double fnum, snum, ans;
    int plus = 1;
    int times = 2;
    int divide = 3;
    int subtract = 4;
    int remainder = 5;
    System.out.println("Enter first num: ");
    fnum = Josh.nextDouble();
    System.out.println("Enter second num: ");
    snum = Josh.nextDouble();
    if ( System.in = 1 ){
    ans = fnum + snum;
    System.out.println(ans);
    }

    }

    }


    /*thats my code*/

  11. #31
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,336
    Blog Entries
    7
    Rep Power
    20

    Default Re: Java

    Quote Originally Posted by JoshieWashiePoo View Post
    if ( System.in = 1 ){
    You can't assign the value 1 to the System.in variable (it's an InputStream); if you had tried to compile this code, the compiler would've told you so.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  12. #32
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Java

    Quote Originally Posted by JoshieWashiePoo View Post
    import java.util.Scanner;


    class Calc {
    public static void main(String args[]){
    Scanner Josh = new Scanner(System.in);
    double fnum, snum, ans;
    int plus = 1;
    int times = 2;
    int divide = 3;
    int subtract = 4;
    int remainder = 5;
    System.out.println("Enter first num: ");
    fnum = Josh.nextDouble();
    System.out.println("Enter second num: ");
    snum = Josh.nextDouble();
    if ( System.in = 1 ){
    ans = fnum + snum;
    System.out.println(ans);
    }

    }

    }


    /*thats my code*/
    Forum Rules
    Guide For New Members
    BB Code List - Java Programming Forum

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  13. #33
    Join Date
    May 2012
    Posts
    28
    Rep Power
    0

    Default Re: Java

    Quote Originally Posted by JosAH View Post
    You can't assign the value 1 to the System.in variable (it's an InputStream); if you had tried to compile this code, the compiler would've told you so.

    kind regards,

    Jos
    I knew it wouldn't work, I just wanted to put SOMETHING there, anyway, how would I make it do what I want it to?

  14. #34
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,336
    Blog Entries
    7
    Rep Power
    20

    Default Re: Java

    Quote Originally Posted by JoshieWashiePoo View Post
    I knew it wouldn't work, I just wanted to put SOMETHING there, anyway, how would I make it do what I want it to?
    If you knew that wouldn't work you should've had an idea how it should work; you've been fiddling with Java for more than two years so you should be able to give it a try yourself. I (for one) am not going to spoonfeed this ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  15. #35
    EscSequenceAlpha is offline Senior Member
    Join Date
    Apr 2012
    Posts
    115
    Rep Power
    0

    Default Re: Java

    Ok josh lets look at your code here but please use the code tags, they're on the toolbar if you reply to thread.

    You get two numbers from the user, fnum and snum.
    now am I to understand you want the user to choose what operation to perform?
    you need a variable to represent the users choice, so you need to assign another varaible in the same way you as fnum and snum
    now that you have the users choice stored as an int you want to find out what that int is and perform the right calculation.
    you could use a list of if statements but consider the switch statement

    I want you too look up the switch statement and try to use it here, remember you need a variable for the users choice for the argument

    come back with your new code thats your task

  16. #36
    Join Date
    May 2012
    Posts
    28
    Rep Power
    0

    Default Re: Java

    i still don't know how to assign the user input to a variable or how to check it.

  17. #37
    romero4742 is offline Member
    Join Date
    Mar 2012
    Posts
    27
    Rep Power
    0

    Default Re: Java

    Quote Originally Posted by JoshieWashiePoo View Post
    i still don't know how to assign the user input to a variable or how to check it.
    Okay why don't you look up the java logical operators they are what you need to compare two items.
    Also, use a java IDE they help you find mistakes and sometimes give you solutions. IDEs compile and run the code for you. You should read about them.
    Oh also it seems like you yet don't understand how to assign values to variables or how to use them. You should take another look at them.

    Java Code:
    System.in
    is not a variable. You are correctly taking in input from the user and assigning it to a variable but you are not using that variable correctly. Good luck.

  18. #38
    EscSequenceAlpha is offline Senior Member
    Join Date
    Apr 2012
    Posts
    115
    Rep Power
    0

    Default Re: Java

    Quote Originally Posted by JoshieWashiePoo View Post
    i still don't know how to assign the user input to a variable or how to check it.
    you just did it here
    System.out.println("Enter first num: ");
    fnum = Josh.nextDouble();

    Josh is a scanner object and nextDouble is a method of the Scanner class that returns input of type double from the keyboard.
    fnum is a variable of type double, you declared it so along with other doubles here:
    double fnum, snum, ans;
    fnum = Josh.nextDouble(); assigns the double returned from Scanner object and puts it into the variable fnum

    fnum contains input from the user.

    what you want to do is use the nextInt() method of the Scanner class to obtain an int and assign it to a int variable... that int will contain the option the user picked (1,2,3)

    you then use a conditional statement to perform a calculation based on the input. for example

    if( choice == 1 )
    {
    ans = fnum + snum;
    }

    System.out.println(ans)

    however if you want to test a single variable for multiple outcomes you should use the switch statement. it will execute different code depending on the the argument (1,2,3); now please try to understand that and come back with a switch statement

    also, I hope your posts dont annoy the great moderators and senior members of this forum (legend has it they were able to code skyrim using only 701 lines of java... or so the legend goes) they expect you to be able to learn things like this by reading on your own.

    I will help you, but they do have a point. attempt a switch statement or something and post it here and I'll take a look

  19. #39
    Join Date
    May 2012
    Posts
    28
    Rep Power
    0

    Default Re: Java

    Java Code:
    import java.util.Scanner;
    
    
    class Calc {
    	public static void main(String args[]){
    		Scanner Josh = new Scanner(System.in);
    		double fnum, snum, ans;
    		Scanner OP = new Scanner(System.in);
    		int op;
    		System.out.println("Enter first num: ");
    		fnum = Josh.nextDouble();
    		System.out.println("Enter the Command (1=+, 2=-, 3=-*, 4=/)");
    		op = OP.nextInt();
    		System.out.println("Enter second num: ");
    		snum = Josh.nextDouble();
    		switch (op){
    		case 1:
    			
    			ans = fnum + snum;
    			System.out.println(ans);
    			break;
    		case 2:
    			ans = fnum - snum;
    			System.out.println(ans);
    			break;
    		case 3:
    			ans = fnum * snum;
    			System.out.println(ans);
    			break;
    		case 4:
    			ans = fnum / snum;
    			System.out.println(ans);
    			break;
    		default: 
    			System.out.println("Invalid Statement.");
    			break;
    			
    		}
    		
    		
    	}
    
    }

  20. #40
    EscSequenceAlpha is offline Senior Member
    Join Date
    Apr 2012
    Posts
    115
    Rep Power
    0

    Default Re: Java

    very good josh.

    one point, you dont need two Scanner objects

    example when you do
    fnum = Josh.nextDouble();
    snum = Josh.nextDouble();

    the Scanner object doesnt keep the input from the previous nextDouble method, instead it gets another input form the user the next time you use nextDouble() method
    but thats ok because you stored the first input in fnum after it was read.

    so you can use the same Scanner object and do op = Josh.nextInt();

    are there any errors? if so post. also are you using an IDE?

    so you could do op = Josh.nextInt() too, you already stored the previous inputs from the Scanner object in fnum and snum respectively

Page 2 of 5 FirstFirst 1234 ... LastLast

Posting Permissions

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