Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1.задача
- import java.util.Scanner;
- public class main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int l = Integer.parseInt(scan.nextLine());
- letters(l);
- }
- public static void letters(int l) {
- char[] letter = "abcdefghijklmnopqrstuvwxyz".toCharArray();
- for(int i =0;i < l; i++ ) {
- System.out.print(letter[i]+" ");
- }
- }
- }
- 2.import java.util.Scanner;
- public class main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int[] a = {2, 6, 4,8};
- int[] b = {2, 6, 4,8};
- boolean yes = true;
- if (a.length == b.length) {
- for (int i = 0; i < a.length; i++) {
- if (a[i] != b[i]) {
- yes = false;
- break;
- }
- if (a[i] == b[i]) {
- yes = true;
- }
- }
- } else {
- yes = false;
- }
- if (yes == false){
- System.out.println("not equals");
- }
- else if (yes == true){
- System.out.println("equals");
- }
- }
- }
- 3.задача
- import java.util.Scanner;
- public class main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- char[] a = "absav".toCharArray();
- char[] b = "absbb".toCharArray();
- if (a.length > b.length) {
- System.out.println("b is sooner in alphabet");
- }
- if (a.length < b.length) {
- System.out.println("a is sooner in alphabet");
- }
- if (a.length == b.length) {
- for (int i = 0; i < a.length; i++) {
- if (a[i]==(b[i])) {
- continue;
- }
- if (a[i]!=b[i]) {
- if (a[i] > b[i]) {
- System.out.println("b is sooner in alphabet");
- }if (a[i] < b[i]) {
- System.out.println("a is sooner in alphabet");
- }
- break;
- }
- }
- }
- }
- }
- 4.задача
- import java.util.Scanner;
- public class main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int[] arr = {2, 1, 1, 2, 3, 3, 2, 2, 2,2, 1,3,3,3,3,3};
- int best = 0;
- int preBest = 0;
- int element = 0;
- int preElement = 0;
- for (int i = 1; i < arr.length; i++) {
- if (arr[i] == arr[i - 1]) {
- best++;
- element = arr[i];
- } else if (arr[i] != arr[i - 1]) {
- preBest = best;
- preElement = element;
- best = 0;
- element = 0;
- }
- }
- if (best < preBest) {
- System.out.print("{");
- for (int s = 0; s < preBest ; s++) {
- System.out.print(preElement + ",");
- }
- System.out.print(preElement + "}");
- }else{
- System.out.print("{");
- for (int s = 0; s < best - 1; s++) {
- System.out.print(element + ",");
- }
- System.out.print(element + "}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement