# Help on Java Coding Decimal and Ternary Operator

• 06-13-2013, 02:31 PM
TheGreenG
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);

}

}
}
• 06-13-2013, 02:42 PM
DarrylBurke
Re: Help on Java Coding Decimal and Ternary Operator