Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class HomeWork_6 {
- // Дана строка, проверить, что она состоит из строчных букв (boolean)
- // - Дан массив, посчитать количество положительрных элементов в нём (int)
- // - Даны два числа, проверить, что число a делится на число b (boolean)
- // - Заменить все отрицательные элементы на ноль в массива (исходные данные можно и нужно менять) (int [])
- // - Проверить, что строка является палиндромом (читается с обеих сторон одинаково)
- static Scanner input = new Scanner(System.in);
- static int[] arrNum = new int[] {1, 3, 7, -4, 5, -7};
- //static int firstNum = new int;
- //static int secondNum = new int;
- static boolean letterWord = true;
- private static boolean checkTheLetterCase() {
- char wordLetter;
- String wordInputed;
- wordInputed = input.next();
- int a = wordInputed.length();
- int b = 0;
- for (int i = 0; i < a; i++) {
- wordLetter = wordInputed.charAt(i);
- if ((wordLetter >= 'A' && wordLetter <= 'Z')||(wordLetter >= 'А' && wordLetter <= 'Я'))
- b=b;
- else b ++;
- }
- if (b < a) letterWord = false;
- return letterWord;
- }
- private static int howManyPositiveElements(int howMany){
- int a = arrNum.length;
- for (int i = 0; i <a ; i++) {
- if (arrNum[i] >= 0)
- howMany += 1;
- }
- return howMany;
- }
- public static void main(String[] args) {
- int howMany = 0;
- System.out.println("Введите слово");
- checkTheLetterCase();
- if (letterWord == true) {
- System.out.println("в введенном слове нет заглавных букв");
- } else{
- System.out.println("в введенном слове есть заглавные буквы");
- }
- howManyPositiveElements(howMany);
- System.out.println("положительных элементов в массиве " + howMany);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement