Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main_input(long[] array){
- Scanner in =new Scanner(System.in);
- for(int i=0;i<array.length;i++){
- array[i]=in.nextLong();
- }
- }
- public static void auto_input(long[] array){
- int n=array.length;
- for (int i=0;i<n;i++){
- array[i]=(long) (Math.random()*999);
- }
- }
- public static void Left_to_right_output(long[] array){
- int n = array.length;
- System.out.print("Массив:");
- for(int i=0;i<n;i++){
- if(i<n-1){
- System.out.print(array[i]+",");
- }else{
- System.out.print(array[i]);
- System.out.println();
- }
- }
- }
- public static boolean Check_value(long[] array,long value){
- for (long x:array){
- if(x==value){
- return true;
- }
- }
- return false;
- }
- public static long[] Bubble_Sort(long[] array){
- int n=array.length;
- for(int i = n-1 ; i > 0 ; i--) {
- for (int j = 0; j < i; j++) {
- if (array[j] > array[j + 1]) {
- long tmp = array[j];
- array[j] = array[j + 1];
- array[j + 1] = tmp;
- }
- }
- }
- return array;
- }
- public static void Right_to_left_output(long[] array){
- int n=array.length;
- System.out.print("Массив:");
- for(int i=n-1;i>=0;--i){
- if(i!=0){
- System.out.print(array[i]+",");
- }else{
- System.out.print(array[i]);
- System.out.println();
- }
- }
- }
- public static void main(String[] args) {
- System.out.println("Укажите размер массива");
- Scanner in = new Scanner(System.in);
- int n = in.nextInt();
- long array[] = new long[n];
- boolean k = true;
- while (k) {
- System.out.println("Меню: ");
- System.out.println("1-Ручной ввод ");
- System.out.println("2-Автоматический ввод");
- System.out.println("3-Вывод слева на право");
- System.out.println("4-Вывод справа налево");
- System.out.println("5-Проверить есть ли указанное значение в массиве");
- System.out.println("6-Отсортировать массив методом пузырька");
- System.out.println("0-Выход");
- String command = in.next();
- if (command.equals("1")) {
- main_input(array);
- }
- if (command.equals("2")) {
- auto_input(array);
- }
- if (command.equals("3")) {
- Left_to_right_output(array);
- in.nextLine();
- in.nextLine();
- }
- if (command.equals("4")) {
- Right_to_left_output(array);
- in.nextLine();
- in.nextLine();
- }
- if (command.equals("5")) {
- System.out.println("Укажите значение:");
- long value = in.nextLong();
- if (Check_value(array,value)){
- System.out.println("Такое значение есть ");
- }else{
- System.out.println("Значения нет ");
- }
- in.nextLine();
- in.nextLine();
- }
- if (command.equals("6")) {
- System.out.println("Отсортированный массив: ");
- Left_to_right_output(Bubble_Sort(array));
- in.nextLine();
- in.nextLine();
- }
- if (command.equals("0")) {
- k=false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement