Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Beginner Code

  1. #1
    Junior Member
    Join Date
    Jan 2021
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Unhappy Beginner Code

     
    import java.util.Scanner;
     
    class Drink {
     
    	String kind;
    	String mass;
    	int price;
    }
     
    public class Tutorial1 {
     
    	public static void main(String[] args) {
     
    		Drink CocaCola = new Drink();
    		CocaCola.kind = "Soda";
    		CocaCola.mass = "2l";
    		CocaCola.price = 2;
     
    		Drink milk = new Drink();
    		milk.kind = "natural";
    		milk.mass = "1 gallon";
    		milk.price = 1;
     
    		Scanner sc = new Scanner(System.in);
     
    		System.out.println("Enter your Drink");
     
    		String text = sc.nextLine();
     
    		while (text != "CocaCola" || text != "milk") {
    			Scanner sc1 = new Scanner(System.in);
     
    			System.out.println("Enter your Drink1");
     
    			String text1 = sc1.nextLine();
     
    			if (text.equals(text1) || text == "milk") {
    				System.out.println("ok viel Spaß beim Film");
    			}
     
    		}
     
    	}
    }
    Last edited by dhaevlidd; January 21st, 2021 at 06:45 AM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Beginner Code

    Don't use == or != to compare the contents of String objects. Use the equals method.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    dhaevlidd (January 21st, 2021)

Similar Threads

  1. hi, beginner. need help with code
    By kittykat0953 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 28th, 2014, 06:32 AM
  2. Help with beginner code
    By KSB Dad in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 13th, 2013, 07:31 AM
  3. Beginner code
    By Skybear in forum What's Wrong With My Code?
    Replies: 11
    Last Post: December 1st, 2012, 07:15 PM
  4. Need Help with code ...beginner
    By Envious1 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 19th, 2012, 08:52 AM
  5. Beginner - Help with my code.
    By eddross in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 12th, 2010, 09:30 AM