Azmain F. answered 07/19/20
Competitive Problem Solver Specializing in Python
Azmain F. answered 07/19/20
Competitive Problem Solver Specializing in Python
Patrick B. answered 07/17/20
Math and computer tutor/teacher
/*****************************************************
Justin: here are the source codes for the FOUR (4)
problems that you have posted....
Sorry, no Python... just java
***************************************************/
import java.io.*;
import java.lang.Math.*;
class Justin
{
private int N;
private int X;
private int Y;
private int Z;
public double CoinProbability()
{
N = PromptForInteger("Please input the # N :>",1,32767);
double prob = 1.0f/ Math.pow(2,N);
System.out.println(" Probability of " + N + " in a row = " + prob);
return(prob);
}
public int GetN() { return(N); }
public int GetX() { return(X); }
public int GetY() { return(Y); }
public int GetZ() { return(Z); }
public void CompareSum()
{
X = PromptForInteger(" Please input the 1st # :>",-15000,15000);
Y = PromptForInteger(" Please input the 2nd # :>",-15000,15000);
Z = PromptForInteger(" Please input the 3rd # :>",-32767,32767);
if ((X+Y)<Z)
{
System.out.println("The total of " + X + "+" + Y + " is LESS Than " + Z);
}
else if ((X+Y)>Z)
{
System.out.println("The total of " + X + "+" + Y + " is GREATER Than " + Z);
}
else
{
System.out.println("The total of " + X + "+" + Y + " is EQUAL to " + Z);
}
}
public int PromptForInteger(String promptMsg, int iMin, int iMax)
{
String inbuff;
Console console;
int iReturn=-1;
do
{
console = System.console();
System.out.print(promptMsg);
inbuff = console.readLine();
iReturn = Integer.parseInt(inbuff);
} while ((iReturn<iMin) || (iReturn>iMax));
return(iReturn);
} //PromptForInteger
public void GradeAverage( int [][] A)
{
double classTotal = 0;
double classAvg = 0;
int N = A.length;
if (N==0) { return;}
int iLoop, jLoop;
for (iLoop=0; iLoop<N; iLoop++)
{
double rowSum = 0;
int rowCount = A[iLoop].length;
for (jLoop=0; jLoop<rowCount; jLoop++)
{
rowSum += A[iLoop][jLoop];
System.out.print(A[iLoop][jLoop] + " ");
}
double rowAvg = rowSum / rowCount;
System.out.println(" row Avg = " + rowAvg);
classTotal += rowAvg;
}
classAvg = classTotal/N;
System.out.println(" Class average = " + classAvg);
}
private int LinearSearch( int [] A, int iTarget)
{
int iReturn=-1;
for (int iLoop=0; iLoop<A.length; iLoop++)
{
if (iTarget==A[iLoop])
{
iReturn = iLoop;
break;
}
}
return(iReturn);
}
private int Max(int [] A)
{
int iMax = -32767;
for (int iLoop=0; iLoop<A.length; iLoop++)
{
if (A[iLoop]>iMax)
{
iMax = A[iLoop];
}
}
return(iMax);
}
public void ShowMultiples()
{
int [] A = {5,13,6,21,17,51,10,33};
int t = PromptForInteger("Please enter the # :>",1,10000);
int N=1;
int n=-32767;
while (n<=Max(A))
{
n=N*t;
if (LinearSearch(A,n)>=0)
{
System.out.println(n);
}
N++;
}
}
public static void main(String args[])
{
Justin x = new Justin();
x.CoinProbability();
x.CompareSum();
int A[][] = {{95,92,86,87},{65,54},{89,72,100},{33,0,0,70}};
x.GradeAverage(A);
x.ShowMultiples();
} //main
} //class
Get a free answer to a quick problem.
Most questions answered within 4 hours.
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.