Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First Epc assignment #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions Ryan/src/AddMatrices.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Created by tenas on 8/3/17.
*/
import java.util.Scanner;

public class AddMatrices {
public static void main(String args[])
{
int m, n, c, d;
Scanner in = new Scanner(System.in);

System.out.println("Enter the number of rows and columns of matrix");
m = in.nextInt();
n = in.nextInt();

int first[][] = new int[m][n];
int second[][] = new int[m][n];
int sum[][] = new int[m][n];

System.out.println("Enter the elements of first matrix");

for ( c = 0 ; c < m ; c++ )
for ( d = 0 ; d < n ; d++ )
first[c][d] = in.nextInt();

System.out.println("Enter the elements of second matrix");

for ( c = 0 ; c < m ; c++ )
for ( d = 0 ; d < n ; d++ )
second[c][d] = in.nextInt();

for ( c = 0 ; c < m ; c++ )
for ( d = 0 ; d < n ; d++ )
sum[c][d] = first[c][d] + second[c][d]; //replace '+' with '-' to subtract matrices

System.out.println("Sum of entered matrices:-");

for ( c = 0 ; c < m ; c++ )
{
for ( d = 0 ; d < n ; d++ )
System.out.print(sum[c][d]+"\t");

System.out.println();
}
}
}


76 changes: 76 additions & 0 deletions Ryan/src/Arrayz.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import java.util.ArrayList;
import java.util.Random;

/*
Created by tenas on 8/3/17.
*/
public class Arrayz {

private int[] a;

public Arrayz(int[] a) {
this.a = a;
}

public int[] getA() {
return a;
}

public void reverseArray(int[] b) {
int temporal;
for(int i=0; i<b.length; i++){
System.out.println(b[b.length-1-i]);
}
}

public void minAndMax(int[] d) {
int max = d[0];
int min = d[0];

for(int a: d){
if(a>max) {
max = a;
}
}
for(int a: d){
if(a<min) {
min = a;
}
}
System.out.println("The Maximum is: " + max + " and the minimum is: " + min);
}

public void commonElements(int[] a, int[] b){
ArrayList<Integer> commonElements = new ArrayList<>();
int counter = 0;
for(int i=0; i<a.length; i++){
for(int k=0; k<b.length; k++){
if(a[i]==b[k])
commonElements.add(a[i]);
}
}
System.out.println("Common elements are: ");
for(int c: commonElements) {
System.out.println( c + " ");
}
}

public void removeDuplicates(int[] a){
Random change = new Random();
for(int i=0; i<a.length; i++){
for(int k=i+1; k<a.length; k++) {
if (a[i] == a[k]) {
a[k] = 1 + change.nextInt(100);//changing one of the duplicates to any random value from 1-100
//hopefully this wouldnt cause another duplicate. Cannot remove the value completly from the array since arrays are not dynamic.
}
}
}
for(int c: a) {
System.out.println( c + " ");
}
}

}



26 changes: 26 additions & 0 deletions Ryan/src/ArrayzTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import java.util.Scanner;

/**
* Created by tenas on 8/3/17.
*/
public class ArrayzTest {
public static void main(String args[]){
Scanner input = new Scanner(System.in);
System.out.println("Enter length of array");
int length = input.nextInt();
System.out.println("Enter elements of array");
int[] x = new int[length];
for (int i = 0; i < x.length; i++){
x[i] = input.nextInt();
}

Arrayz array = new Arrayz(x);
//array.reverseArray(x);
//array.minAndMax(x);
//array.commonElements(x,y); to use this, create another array y
array.removeDuplicates(x);
}
}



24 changes: 24 additions & 0 deletions Ryan/src/ReplaceLetter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import java.util.Scanner;

/**
* Created by tenas on 8/3/17.
*/
public class ReplaceLetter {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter a word");
String name = input.nextLine();
char[] a = new char[name.length()];
for (int i = 0; i < a.length; i++)
a[i] = name.charAt(i);
System.out.println("Enter a position of therletter in the word which you want to change");
int n = input.nextInt();
a[n-1] ='*';
System.out.print("Modified word becomes ");
for(char c: a){

System.out.print(c + " ");
}
}
}