Starting git repo for working on files
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,24 @@
|
||||
public class BandMatrix
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
int n = Integer.parseInt(args[0]);
|
||||
int width = Integer.parseInt(args[1]);
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
for (int j = 0; j < n; j++)
|
||||
{
|
||||
if ((j - i <= width) && (i -j <= width))
|
||||
{
|
||||
System.out.print(" * ");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.print(" 0 ");
|
||||
}
|
||||
}
|
||||
System.out.println("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,23 @@
|
||||
public class GeneralizedHarmonic
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
int n = Integer.parseInt(args[0]);
|
||||
int r = Integer.parseInt(args[1]);
|
||||
if (r >= 0 && n >= 0)
|
||||
{
|
||||
double h = 0;
|
||||
double breuk = 0;
|
||||
for (int i = 1; i <= n; i++ )
|
||||
{
|
||||
breuk = 1/(Math.pow(i,r));
|
||||
h += breuk;
|
||||
}
|
||||
System.out.println(h);
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Negative number in one of the arguments");
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,25 @@
|
||||
public class RandomWalker
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
int r = Integer.parseInt(args[0]);
|
||||
|
||||
int xCoordinate = 0;
|
||||
int yCoordinate = 0;
|
||||
int steps = 0;
|
||||
|
||||
System.out.println("(" + xCoordinate + ", " + yCoordinate + ")" );
|
||||
|
||||
while(Math.abs(xCoordinate) + Math.abs(yCoordinate) < r)
|
||||
{
|
||||
if(Math.random() <= 0.25) xCoordinate += 1;
|
||||
else if (Math.random() <= 0.50) xCoordinate -= 1;
|
||||
else if (Math.random() <= 0.75) yCoordinate += 1;
|
||||
else yCoordinate -= 1;
|
||||
|
||||
System.out.println("(" + xCoordinate + ", " + yCoordinate + ")" );
|
||||
steps++;
|
||||
}
|
||||
System.out.println("steps = " + steps);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,31 @@
|
||||
public class RandomWalkers
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
int r = Integer.parseInt(args[0]);
|
||||
int trials = Integer.parseInt(args[1]);
|
||||
|
||||
int xCoordinate = 0;
|
||||
int yCoordinate = 0;
|
||||
int steps = 0;
|
||||
double average = 0;
|
||||
|
||||
//System.out.println("(" + xCoordinate + ", " + yCoordinate + ")" );
|
||||
|
||||
for(int i = 1; i <= trials; i++)
|
||||
{
|
||||
while(Math.abs(xCoordinate) + Math.abs(yCoordinate) < r)
|
||||
{
|
||||
if(Math.random() <= 0.25) xCoordinate += 1;
|
||||
else if (Math.random() <= 0.50) xCoordinate -= 1;
|
||||
else if (Math.random() <= 0.75) yCoordinate += 1;
|
||||
else yCoordinate -= 1;
|
||||
|
||||
//System.out.println("(" + xCoordinate + ", " + yCoordinate + ")" );
|
||||
steps++;
|
||||
}
|
||||
}
|
||||
average = (float) steps / trials;
|
||||
System.out.println("average number of steps = " + average);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Reference in New Issue
Block a user