Results 1 to 2 of 2
  1. #1
    TheGreenG is offline Member
    Join Date
    Jun 2013
    Posts
    1
    Rep Power
    0

    Default Help on Java Coding Decimal and Ternary Operator

    Hi,

    I'm new to Java currently 3rd meeting on our Java class.
    So I already have the code but my professor wants us to edit it a bit. Here are the 3 of my final code that needs tweaking.

    -----------------------------------------
    1.) Add 2 decimal places on the final answer
    -----------------------------------------
    public class Lab2D{
    public static void main(String [] args){

    double T, Q, Q1 = 80, Q2 = 83, Q3 = 93, AS, AS1 = 75, AS2 = 100, LQ, LQ1= 100, LQ2 = 85, FE, FE1 = 85;

    Q = (0.25*((Q1+Q2+Q3)/3));
    AS = (0.10*((AS1+AS2)/2));
    LQ = (0.25*((LQ1+LQ2)/2));
    FE = (0.40*(FE1));

    DecimalFormat T = (Q+AS+LQ+FE);

    System.out.println("The Total Grade is: " +T);

    }
    }


    -----------------------------------------
    2.) Add 2 decimal places on the final answer
    -----------------------------------------
    public class Kompute {
    Public Statis void main (String [] args){
    int x = 15, y = 10, z = 5, K;
    k = (x+y+z)/3;
    system.out.println("The Average of three numbers is:" + k);
    }
    }


    -----------------------------------------
    3.) Use Ternary Operator
    -----------------------------------------
    public class LabGreatest{
    public static void main(String [] args){

    int xnum = 3, ynum = 4, znum = 5;

    //Greater Than
    if (xnum > ynum && xnum > znum){

    System.out.println("The greatest number is:" + xnum);
    }


    else if(ynum > znum && ynum > xnum){

    System.out.println("The greatest number is:" + ynum);
    }

    else if(znum > xnum && znum > ynum);{

    System.out.println("The greatest number is:" + znum);

    }





    //Less Than
    if (xnum < ynum && xnum < znum){

    System.out.println("The least number is:" + xnum);
    }


    else if(ynum < znum && ynum < xnum){

    System.out.println("The least number is:" + ynum);
    }
    else if(znum < xnum && znum < ynum);{

    System.out.println("The least number is:" + znum);

    }


    }
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: Help on Java Coding Decimal and Ternary Operator

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

Similar Threads

  1. Replies: 5
    Last Post: 01-21-2012, 11:02 PM
  2. Shorthand ternary operator ?
    By Billywizz in forum New To Java
    Replies: 3
    Last Post: 10-02-2011, 09:57 PM
  3. doubt regarding ternary operator (?)
    By subith86 in forum New To Java
    Replies: 2
    Last Post: 03-10-2011, 08:15 AM
  4. Use of ternary
    By wulfgarpro in forum New To Java
    Replies: 1
    Last Post: 09-21-2010, 06:31 AM
  5. Replies: 2
    Last Post: 02-27-2010, 07:10 AM

Tags for this Thread

Posting Permissions

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