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, need help with basic code

  1. #1
    Junior Member
    Join Date
    Sep 2024
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Beginner, need help with basic code

    I have a task where i input x and y coordinates and it tells me if it's gray or white, i can't post a picture of the graph but entering most of the coordinates is accurate, but whenever i enter x=1 and y=1 or x=0 y=0 it shows gray even though it's completely white, i want to understand why it's not showing white. I think i have entered all the formulas correctly, there's a gray circle, gray triangle and a white cube in the middle of the triangle
    import java.util.Scanner;
     
    public class Main {
     
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            System.out.println("241RDB125");
            System.out.println("16. variants");
     
            double x, y;
            System.out.print("x = ");
            x = sc.nextDouble();
            System.out.print("y = ");
            y = sc.nextDouble();
     
            System.out.println("Result:");
     
            boolean white1 = (x >= 6 && x <= 7 && y >= 4 && y <= 5);
            boolean grey1 = ((x - 3) * (x - 3) + (y - 3) * (y - 3) >= 4);
            boolean grey2 = (y <= 7 && x <= 8 && y <= x + 1);
     
            if (white1) {
                System.out.println("white");
            } else if (grey1 || grey2) {
                System.out.println("grey");
            } else {
                System.out.println("white");
            }
     
            sc.close();
        }
    }
    Last edited by Norm; September 18th, 2024 at 08:22 AM. Reason: Added code tags

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

    Default Re: Beginner, need help with basic code

    Why do you think the output is incorrect? Can you post the equations with the values of the variables that shows what you expect?

    What are the rules to determine whether to show white or grey?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Beginner Developer with Basic Computer Requirement Questions
    By akrohn in forum Java Theory & Questions
    Replies: 4
    Last Post: April 2nd, 2020, 03:44 AM
  2. I'm a beginner and i'm searching for a basic example
    By mottogo in forum Java Theory & Questions
    Replies: 4
    Last Post: June 10th, 2014, 07:43 AM
  3. I'm a beginner and i'm searching for a basic example
    By mottogo in forum Object Oriented Programming
    Replies: 0
    Last Post: June 9th, 2014, 06:10 AM
  4. Problem with basic calculator - Beginner
    By Dream Hacked in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 25th, 2013, 11:00 PM
  5. Basic Beginner Help
    By SRD in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 11th, 2010, 04:27 PM