Advertisement
lemansky

Untitled

Feb 28th, 2023
658
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.28 KB | None | 0 0
  1. package excercise1;
  2.  
  3. import java.util.*;
  4.  
  5. public class JavaTasks {
  6.  
  7.     public static void main(String[] args) {
  8.          
  9. //        task2();
  10. //        task3();
  11. //        task4();
  12. //          task5();
  13. //          task6();          
  14.           task8();
  15.  
  16.     }
  17.    
  18.     static void task2(){
  19.         Scanner reader = new Scanner(System.in);
  20.         System.out.println("Please enter first name:");
  21.         String f_name = reader.nextLine();
  22.         System.out.println("Please enter last name:");
  23.         String l_name = reader.nextLine();
  24.         System.out.println(f_name + " " + l_name);
  25.     }
  26.    
  27.     static void task3(){
  28.         Scanner reader = new Scanner(System.in);
  29.         System.out.println("Please enter first num1:");
  30.         int num1 = reader.nextInt();
  31.         System.out.println("Please enter last num2:");
  32.         int num2 = reader.nextInt();
  33.        
  34.         if(num1 > num2){
  35.             System.out.println("first is greater");
  36.         } else if(num2 > num1) {
  37.             System.out.println("second is greater");
  38.         } else {
  39.             System.out.println("numbers are equal");
  40.         }
  41.        
  42.     }
  43.    
  44.     static void task4(){
  45.         Scanner reader = new Scanner(System.in);
  46.         System.out.println("Please enter num1:");
  47.         int num1 = reader.nextInt();
  48.         if(num1 % 2 == 0){
  49.             System.out.println("Yes");
  50.         } else {
  51.             System.out.println("No");
  52.         }
  53.     }
  54.    
  55.     static void task5(){
  56.         Scanner reader = new Scanner(System.in);
  57.         System.out.println("Please enter num1:");
  58.         int num1 = reader.nextInt();
  59. //        if(num1 < 0 && num1 > 9){
  60. //            System.out.println("Exception: not supported");
  61. //        } else {
  62.             switch(num1) {
  63.                 case 0: System.out.println("zero"); break;
  64.                 case 1: System.out.println("one"); break;                
  65.                 case 2: System.out.println("two"); break;
  66.                 case 3: System.out.println("three"); break;
  67.                 case 4: System.out.println("four"); break;
  68.                 case 5: System.out.println("five"); break;
  69.                 case 6: System.out.println("six"); break;
  70.                 case 7: System.out.println("seven"); break;                
  71.                 case 8: System.out.println("eight"); break;
  72.                 case 9: System.out.println("nine"); break;
  73.                 default: System.out.println("Exception: not supported"); break;
  74.             }
  75. //        }
  76.        
  77.     }
  78.    
  79.     static void task6(){
  80.         Scanner reader = new Scanner(System.in);
  81.         System.out.println("Please enter word:");
  82.         String word = reader.nextLine();
  83.         System.out.println("Please enter symbol:");
  84.         String c = reader.nextLine();
  85. //        int count = 0;
  86. //        for (int i = 0; i < word.length(); i++) {
  87. //            if(word.indexOf(c) > -1){
  88. //                System.out.println(count + word.indexOf(c) + 1);
  89. //                count = word.indexOf(c) + 1;
  90. //                word = word.substring(word.indexOf(c) + 1);
  91. //            }
  92. //        }
  93.         for (int i = 0; i < 10; i++) {
  94.             if(word.charAt(i) == c.charAt(0)){
  95.                 System.out.println(i + 1);
  96.             }
  97.         }
  98. //        String s = "Boris";
  99. //        String p = "Boris";
  100. //        if(s == p) you cannot compare strings with ==, you can compare in JS and PHP
  101. //        if(s.equals(p)) - proper way to compare strings
  102.        
  103.     }
  104.      
  105.     static void task7(){
  106.         Scanner reader = new Scanner(System.in);
  107.         System.out.println("Please enter word1:");
  108.         String word1 = reader.nextLine();
  109.         System.out.println("Please enter word2:");
  110.         String word2 = reader.nextLine();
  111.         if(word1.length() > word2.length()){
  112.             System.out.println("first");
  113.         } else if(word1.length() < word2.length()) {
  114.             System.out.println("second");
  115.         } else {
  116.             System.out.println("equal length");
  117.         }
  118. //        int[] arr = {1, 2, 3};
  119. //        arr.length
  120. //        
  121. //        ArrayList<Integer> ar = new ArrayList<Integer>();
  122. //        ar.add(1);
  123. //        ar.size();
  124.     }
  125.    
  126.     static void task8(){
  127.         for (int i = 10; i > 0; i--) {
  128.             System.out.println(i);
  129.         }
  130.     }
  131. }
  132.  
Tags: EX
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement