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(String[] args) {
- int n=0, i;
- int[] array;
- boolean isIncorrect;
- Scanner scan = new Scanner(System.in);
- do {
- isIncorrect = false;
- System.out.println("Введите колличество элементов в массиве: ");
- try {
- n = Integer.parseInt(scan.nextLine()) - 1;
- }
- catch (Exception e) {
- System.err.println("Неверный ввод данных!");
- isIncorrect = true;
- }
- } while (isIncorrect);
- array = new int[n];
- for (i = 0; i <= n; ++i) {
- do {
- isIncorrect = false;
- System.out.println("Введите " + (i+1) + " элемент массива");
- try {
- array[i] = Integer.parseInt(scan.nextLine());
- }
- catch (Exception e) {
- System.err.println("Неверный ввод данных!");
- isIncorrect = true;
- }
- } while (isIncorrect);
- scan.close();
- }
- System.out.println("Вывод на экран: ");
- for (i = 0; i <= n; ++i){
- if (i % 2 ==1) {
- System.out.print(array[i] + ", ");
- }
- else {
- System.out.println("-" + array[i] + ", ");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement