Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Arrays;
- import static jdk.nashorn.internal.objects.NativeString.charAt;
- public class Main {
- public static void main(String[] args) {
- Main lab1 = new Main();
- lab1.compulsory();
- lab1.optional(args);
- }
- static int computedN() {
- int n = (int) (Math.random() * 1_000_000);
- n = n * 3;
- n = n + 0b10101;
- n = n + 0xff;
- n = n * 6;
- return n;
- }
- static int recSum(int n) {
- int sum = 0;
- do {
- sum = 0;
- while (n != 0) {
- sum = sum + n % 10;
- n = n / 10;
- }
- System.out.println(sum);
- System.out.println('\n');
- n = sum;
- } while (n > 10);
- return n;
- }
- void compulsory() {
- System.out.println("Hello World!");
- String[] languages = {"C", "C++", "C#", "Python", "Go", "Rust", "JavaScript", "PHP", "Swift", "Java"};
- int result = computedN();
- result = recSum(result);
- System.out.println("Willy-nilly, this semester I will learn " + languages[result] + '.');
- }
- public String[] generate(int n, int k, char[] alphabet) {
- String[] words = new String[n];
- for (int i = 0; i < n; i++) {
- StringBuilder sb = new StringBuilder();
- for (int j = 0; j < k; j++) {
- int pos = (int) (Math.random() * (alphabet.length + 1)) - 1;
- if (pos < 0) pos=0;
- sb.append(alphabet[pos]);
- }
- words[i] = sb.toString();
- }
- return words;
- }
- void optional(String[] args) {
- if (args.length < 6) {
- System.out.println("Not enough arguments!");
- System.exit(-1);
- } else {
- //alte validari este int sau char
- int wordLg = Integer.parseInt(args[1]);
- int nbWords = Integer.parseInt(args[0]); //how many words to generate
- final int alphabetSize = args.length - 2; //how many characters has the alphabet
- char[] myAlphabet = new char[alphabetSize]; //create the alphabet array
- int l,c;
- int i;
- for (i = 0; i < alphabetSize; i++) //
- myAlphabet[i] = args[i + 2].charAt(0);//converteste in char stringul gasit la poz curenta
- System.out.println("That is your alphabet : ");
- System.out.println(myAlphabet);
- String[] words = generate(nbWords, wordLg, myAlphabet);
- System.out.println("These are your random generated words : ");
- for( i=0;i< nbWords;i++){
- System.out.println(words[i]);
- }
- int[][] isAd = new int[nbWords][nbWords];
- for (l = 1; l <= nbWords; l++)
- for (c = 1; c <= nbWords; c++)
- isAd[l][c] = check(words, l,c, wordLg);
- for (int[] row : isAd)
- System.out.println(Arrays.toString(row));
- }
- }
- public int check(String[] words,int i,int j,int n)
- {
- for (int p1=0;p1<=n;p1++)
- for(int p2=0;p2<n;p2++)
- if( (int)words[i].charAt(p1)==(int)words[j].charAt(p2)) return 1;
- return 0;
- }
- void bonus() {
- //Do stuff
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement