NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io


public class Main
{
public static void main(String[] args)
{
task01();
task02();
task03();
task04();
//task05();
}

private static void task01()
{
int arr[][] = new int[8][8];

for (int i = 0; i < arr.length; ++i)
{
for (int j = 0; j < arr[i].length; ++j)
{
arr[i][j] = (int) (Math.random() * 10);
}
}

System.out.println(threeSameNumbersOccur(arr));
}

private static boolean threeSameNumbersOccur(int[][] arr)
{
int occurrences = 0;

for (int n = 0; n < 10; ++n)
{
occurrences = 0;
for (int i = 0; i < arr.length; ++i)
{
if (arr[i][i] == n || arr[arr.length - i - 1][arr.length - i - 1] == n)
{
occurrences++;
}
}

if (occurrences >= 3)
{
return true;
}
}


return false;
}

private static void task02()
{
char arr[][] = new char[10][10];

for (int i = 0; i < arr.length; ++i)
{
for (int j = 0; j < arr[i].length; ++j)
{
arr[i][j] = (char) ((Math.random() * 'z' - 'a' + 1) + 'a');
}
}

System.out.println(threeGreaterNumbersExist(arr));
}

private static boolean threeGreaterNumbersExist(char[][] arr)
{
char[] singleArray = toSingleArray(arr);

for (int i = 0; i < singleArray.length - 2; ++i)
{
if (singleArray[i + 2] > singleArray[i + 1] && singleArray[i + 1] > singleArray[i])
{
return true;
}
}

return false;
}

private static char[] toSingleArray(char arr[][])
{
char[] returnArray = new char[arr.length * 2 - 1 + arr[0].length * 2 - 1];
int arrIndex = 0;

for (int i = 0; i < arr.length; ++i)
{
if (i == 0 || i == arr.length - 1)
{
for (int j = 0; j < arr[0].length; ++j)
{
returnArray[arrIndex++] = arr[i][j];
}
}
else
{
returnArray[arrIndex++] = arr[i][0];
returnArray[arrIndex++] = arr[i][arr.length - 1];
}
}

return returnArray;
}

private static void task03()
{
//isEqual();
}

private static void task04()
{
char[][] level = new char[6][6];

char nextPlayer = 'x';

for (int i = 0; i < level.length; ++i)
{
for (int j = 0; j < level.length; ++j)
{
int arr[];

do
{
arr = rollDice();
} while (level[arr[0] - 1][arr[1] - 1] != 0);

level[arr[0] - 1][arr[1] - 1] = nextPlayer;

nextPlayer = (nextPlayer == 'x') ? 'o' : 'x';
}
}

for(var x: level)
{
for(var y: x)
{
System.out.print(y);
}
System.out.println();
}
}

private static int[] rollDice()
{
int[] arr = new int[2];
arr[0] = (int) ((Math.random() * 6 + 1 - 1) + 1);
arr[1] = (int) ((Math.random() * 6 + 1 - 1) + 1);

return arr;
}

// private static void task05()
// {
// char[][] level = new char[3][3];
//
// System.out.println(isWinImpossible(level));
// }
//
// private static boolean isWinImpossible(char[][] level)
// {
//
// }

@SuppressWarnings("unused")
private static boolean isEqual(int[][] arr1, int [][]arr2)
{
if (arr1.length != arr2.length)
{
return false;
}

for (int i = 0; i < arr1.length; ++i)
{
if (arr1[i].length != arr2[i].length)
{
return false;
}
}

for (int i = 0; i < arr1.length; ++i)
{
for (int j = 0; j < arr1[i].length; ++j)
{
if (arr1[i][j] != arr2[i][j])
{
return false;
}
}
}

return true;
}
}
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.