[go: up one dir, main page]

0% found this document useful (0 votes)
32 views6 pages

Rock Paper and Scissor (Java)

The document contains 5 programs for performing matrix operations (addition, subtraction, multiplication, division) and for transposing a matrix in C++. It also contains a Java program to play a game of rock paper scissors between a user and computer by randomly generating the computer's choice, checking the results, and declaring a winner.

Uploaded by

virecey444
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views6 pages

Rock Paper and Scissor (Java)

The document contains 5 programs for performing matrix operations (addition, subtraction, multiplication, division) and for transposing a matrix in C++. It also contains a Java program to play a game of rock paper scissors between a user and computer by randomly generating the computer's choice, checking the results, and declaring a winner.

Uploaded by

virecey444
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

program1: Addition of matrix:

#include<iostream>
using namespace std;
int main()
{
int a[9][9], b[9][9];
cout<<"Enter the elements of matrix: "<<endl;
for(int i = 0;i < 3;i++)
{
for(int j = 0;j < 3;j++)
{
cin>>a[i][j];

}
cout<<"Enter the elements of another matrix: "<<endl;
for(int i = 0;i < 3;i++)
{
for(int j = 0;j < 3;j++)
{
cin>>b[i][j];

}
cout<<endl;
for(int i = 0;i < 3;i++)
{
for(int j = 0;j < 3;j++)
{
cout<<a[i][j]<<ends;

}
cout<<ends<<ends<<ends;
for(int j = 0;j < 3;j++)
{
cout<<b[i][j]<<ends;

}
cout<<endl;

}
cout<<endl<<endl;

for(int i = 0;i < 3;i++)


{
for(int j = 0;j < 3;j++)
{
cout<<a[i][j] + b[i][j]<<ends;

}
cout<<endl;
}
return 0;
}
-----------------------------------------------------------------------------
program to subtract 2 matrix:
#include<iostream>
using namespace std;
int main()
{
int a[9][9], b[9][9];
cout<<"Enter the elements of matrix: "<<endl;
for(int i = 0;i < 3;i++)
{
for(int j = 0;j < 3;j++)
{
cin>>a[i][j];

}
cout<<"Enter the elements of another matrix: "<<endl;
for(int i = 0;i < 3;i++)
{
for(int j = 0;j < 3;j++)
{
cin>>b[i][j];

}
cout<<endl;
for(int i = 0;i < 3;i++)
{
for(int j = 0;j < 3;j++)
{
cout<<a[i][j]<<ends;

}
cout<<ends<<ends<<ends;
for(int j = 0;j < 3;j++)
{
cout<<b[i][j]<<ends;

}
cout<<endl;

}
cout<<endl<<endl;

for(int i = 0;i < 3;i++)


{
for(int j = 0;j < 3;j++)
{
cout<<a[i][j] - b[i][j]<<ends;

}
cout<<endl;
}
return 0;
}
-----------------------------------------------------------------------------------
------------------------
program:3 To multiply two matrix:
#include<iostream>
using namespace std;
int main()
{
int a[9][9], b[9][9];
cout<<"Enter the elements of matrix: "<<endl;
for(int i = 0;i < 3;i++)
{
for(int j = 0;j < 3;j++)
{
cin>>a[i][j];

}
cout<<"Enter the elements of another matrix: "<<endl;
for(int i = 0;i < 3;i++)
{
for(int j = 0;j < 3;j++)
{
cin>>b[i][j];

}
cout<<endl;
for(int i = 0;i < 3;i++)
{
for(int j = 0;j < 3;j++)
{
cout<<a[i][j]<<ends;

}
cout<<ends<<ends<<ends;
for(int j = 0;j < 3;j++)
{
cout<<b[i][j]<<ends;

}
cout<<endl;

}
cout<<endl<<endl;

for(int i = 0;i < 3;i++)


{
for(int j = 0;j < 3;j++)
{
cout<<a[i][j] + b[i][j]<<ends;

}
cout<<endl;
}
return 0;
}
-----------------------------------------------------------------------------------
----
program4: to divide 2 matrix:
#include<iostream>
using namespace std;
int main()
{
int a[9][9], b[9][9];
cout<<"Enter the elements of matrix: "<<endl;
for(int i = 0;i < 3;i++)
{
for(int j = 0;j < 3;j++)
{
cin>>a[i][j];

}
cout<<"Enter the elements of another matrix: "<<endl;
for(int i = 0;i < 3;i++)
{
for(int j = 0;j < 3;j++)
{
cin>>b[i][j];

}
cout<<endl;
for(int i = 0;i < 3;i++)
{
for(int j = 0;j < 3;j++)
{
cout<<a[i][j]<<ends;

}
cout<<ends<<ends<<ends;
for(int j = 0;j < 3;j++)
{
cout<<b[i][j]<<ends;

}
cout<<endl;

}
cout<<endl<<endl;

for(int i = 0;i < 3;i++)


{
for(int j = 0;j < 3;j++)
{
cout<<a[i][j] / b[i][j]<<ends;

}
cout<<endl;
}
return 0;
}
-----------------------------------------------------------------------------------
program5 : to transpose a matrixx\:
#include<iostream>
using namespace std;
int main()
{
int a[9][9], b[9][9],i,j;
cout<<"Enter the elements of matrix: "<<endl;
for( i = 0;i < 3;i++)
{
for( j = 0;j < 3;j++)
{
cin>>a[i][j];
}
}
for( i = 0;i < 3;i++)
{
for( j = 0;j < 3;j++)
{
cout<<a[j][i]<<ends;
}
cout<<endl;
}

return 0;
}
-----------------------------------------------------------------------------------
-----------------

import java.util.Scanner;
import java.util.Random;
class hello{

public static void main(String[] args) {


int n;
Scanner s = new Scanner(System.in);
Random r = new Random();
do {
// getting user choice
int x = r.nextInt(2);
System.out.println("Enter 1 for paper\nEnter 2 for stone\nEnter 3 for
scissor\nEnter 4 to exit");
n = s.nextInt();
// what user choice point
if (n == 1) {
System.out.println("That means you shows paper");
} else if (n == 2) {
System.out.println("That means you shows stone");
} else if (n == 3) {
System.out.println("That means you shows scissor");
}
else if(n == 4){
System.out.println("Thanks for playing ");
}
else {

System.out.println("Oops invalid result");


continue;
}
System.out.println("So the system choice is " + ++x);
if (x == 1) {
System.out.println("That means sys shows paper");
} else if (x == 2) {
System.out.println("That means sys shows stone");
} else if (x == 3) {
System.out.println("That means sys shows scissor");
}

if(n >= 1 && n <= 3) { //hiding random no if user exits


//generating sys choice
//what sys choice points
}
//Checking winner
if (x == 1 && n == 1) {
System.out.println("Its a tie");
}
else if (x == 1 && n ==2) {
System.out.println("sys win");
}
else if (x == 1 && n == 3) {
System.out.println("congo you win");
}

if (x == 2 && n == 1) {
System.out.println("congo you win");
}
else if (x == 2 && n ==2) {
System.out.println("Its a tie");
}
else if (x ==2 && n == 3) {
System.out.println("sys win");
}
if (x == 3 && n == 1) {
System.out.println("sys win");
}
else if (x ==3 && n ==2) {
System.out.println("congo you win");
}
else if (x == 3 && n == 3) {
System.out.println("it is tie");
}
}while(n != 4);
}
}

You might also like