Professional Documents
Culture Documents
import java.util.*;
class Babylonia
{
double n;
double guess;
double r;
double previousGuess;
double diff;
}
public void Square_root()
{
guess = n / 2;
do
{
r = n / guess;
previousGuess = guess;
guess = (guess + r) / 2;
diff = (previousGuess - guess) / ( previousGuess);
}
while(diff >= 0.01);
//for double to two decimal places
System.out.printf("The square root of %.2f is approximately: %.2f\n", n, guess);
}
}
public class Result_Babylonia
{
public static void main(String a[])
{
System.out.println("This is the main class");
Babylonia obj1=new Babylonia();
obj1.data_input();
obj1.Square_root();
}
}
QUESTION N02:
import java.text.DecimalFormat;
import java.util.Random;
for(int i=1;i<=10000;i++){
dice1=ra.nextInt(6)+1;
dice2=ra.nextInt(6)+1;
sum=dice1+dice2;
if(sum==7 || sum==11 )
{
win++;
}
else if(sum==2||sum==3||sum==12)
{
lose++;
}
else
{
point=sum;
dice1=ra.nextInt(6)+1;
dice2=ra.nextInt(6)+1;
sum=dice1+dice2;
while(sum!=7 && sum!=point)
{
dice1=ra.nextInt(6)+1;
dice2=ra.nextInt(6)+1;
sum=dice1+dice2;
}
if(sum==7)
{
lose++;
}
else if(sum==point)
{
win++;
}
dice1=ra.nextInt(6)+1;
dice2=ra.nextInt(6)+1;
}
}
double prob=(win/(lose+win));
System.out.println("Won: "+win+" Lost:"+lose);
System.out.println("Wining Percentage: "+g.format(prob));
if(win>lose)
{
System.out.println("You Win!");
}
else
{
System.out.println("House Wins! and he will win more than you...");
}
QUESTION NO 3
import java.util.Scanner;
class HeightDemo
{
public void input()
{
String genderChild, units, userChoice;
int fatherHeight, motherHeight, childHeight;
QUESTION NO 4:
import java.util.Scanner;
class TestDemo
{
double cost ;
double inflation;
int years;
double expectedCost;
QUESTION N0 5:
public class InterestCalculator
{
private static final double COST_OF_STEREO_SYSTEM = 1000.00;
private static final double INTEREST_RATE_PER_YEAR = 0.18;
private static final double MONTHLY_PAYMENT = 50.00;
numberOfMonths++;
totalInterest += interest;
}
QUESTION N0 6:
import java.util.Scanner;
class GreenCrudPopulation
{
char repeat;
}
}
public class Result_GreenCrudPopulation
{
public static void main(String a[])
{
System.out.println("This is the main class");
GreenCrudPopulation obj1=new GreenCrudPopulation();
obj1.data_input();
}
}
QUESTION N0 7:
import java.util.Scanner;
class Fact
{
public void input()
{
Scanner keyboard = new Scanner(System.in);
int x;
int n;
int k;
double fact;
double result;
char repeat;
do
{
System.out.print("Enter a value of x: ");
x = keyboard.nextInt();
result = 0;
keyboard.close();
}
}
public class expression
{
public static void main(String a[])
{
System.out.println("This is the main class");
Fact obj1=new Fact();
obj1.input();
}
}
QUESTION N0 8:
class CryptarithmeticPuzzle
{
public void cal()
{
for (int T = 0; T <= 9; T++)
{
for (int O = 0; O <= 9; O++)
{
for (int G = 0; G <= 9; G++)
{
for (int D = 0; D <= 9; D++)
{
if (T != O && T != D && T != G && G != O && G
!= D && D != O)
{
int too = (100 * T) + (10 * O) + O;
int good = (1000 * G) + (100 * O) + (10 *
O) + D;
if (4 * too == good)
{
System.out.println("TOO + TOO
+ TOO + TOO = "
+ (4 * too));
System.out.println("GOOD = " +
good);
System.out.println("Therefore, T
="+T
+ ", O = " + O + ", G
="+G
+ ", and D = " + D);
System.out.println();
}
}
}
}
}
}
public class cryptarithmetic
{
public static void main(String a[])
{
System.out.println("This is the main class");
CryptarithmeticPuzzle obj1=new CryptarithmeticPuzzle();
obj1.cal();
}
}