Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package excercise1;
- import java.util.*;
- public class JavaTasks {
- public static void main(String[] args) {
- // task2();
- // task3();
- // task4();
- // task5();
- // task6();
- task8();
- }
- static void task2(){
- Scanner reader = new Scanner(System.in);
- System.out.println("Please enter first name:");
- String f_name = reader.nextLine();
- System.out.println("Please enter last name:");
- String l_name = reader.nextLine();
- System.out.println(f_name + " " + l_name);
- }
- static void task3(){
- Scanner reader = new Scanner(System.in);
- System.out.println("Please enter first num1:");
- int num1 = reader.nextInt();
- System.out.println("Please enter last num2:");
- int num2 = reader.nextInt();
- if(num1 > num2){
- System.out.println("first is greater");
- } else if(num2 > num1) {
- System.out.println("second is greater");
- } else {
- System.out.println("numbers are equal");
- }
- }
- static void task4(){
- Scanner reader = new Scanner(System.in);
- System.out.println("Please enter num1:");
- int num1 = reader.nextInt();
- if(num1 % 2 == 0){
- System.out.println("Yes");
- } else {
- System.out.println("No");
- }
- }
- static void task5(){
- Scanner reader = new Scanner(System.in);
- System.out.println("Please enter num1:");
- int num1 = reader.nextInt();
- // if(num1 < 0 && num1 > 9){
- // System.out.println("Exception: not supported");
- // } else {
- switch(num1) {
- case 0: System.out.println("zero"); break;
- case 1: System.out.println("one"); break;
- case 2: System.out.println("two"); break;
- case 3: System.out.println("three"); break;
- case 4: System.out.println("four"); break;
- case 5: System.out.println("five"); break;
- case 6: System.out.println("six"); break;
- case 7: System.out.println("seven"); break;
- case 8: System.out.println("eight"); break;
- case 9: System.out.println("nine"); break;
- default: System.out.println("Exception: not supported"); break;
- }
- // }
- }
- static void task6(){
- Scanner reader = new Scanner(System.in);
- System.out.println("Please enter word:");
- String word = reader.nextLine();
- System.out.println("Please enter symbol:");
- String c = reader.nextLine();
- // int count = 0;
- // for (int i = 0; i < word.length(); i++) {
- // if(word.indexOf(c) > -1){
- // System.out.println(count + word.indexOf(c) + 1);
- // count = word.indexOf(c) + 1;
- // word = word.substring(word.indexOf(c) + 1);
- // }
- // }
- for (int i = 0; i < 10; i++) {
- if(word.charAt(i) == c.charAt(0)){
- System.out.println(i + 1);
- }
- }
- // String s = "Boris";
- // String p = "Boris";
- // if(s == p) you cannot compare strings with ==, you can compare in JS and PHP
- // if(s.equals(p)) - proper way to compare strings
- }
- static void task7(){
- Scanner reader = new Scanner(System.in);
- System.out.println("Please enter word1:");
- String word1 = reader.nextLine();
- System.out.println("Please enter word2:");
- String word2 = reader.nextLine();
- if(word1.length() > word2.length()){
- System.out.println("first");
- } else if(word1.length() < word2.length()) {
- System.out.println("second");
- } else {
- System.out.println("equal length");
- }
- // int[] arr = {1, 2, 3};
- // arr.length
- //
- // ArrayList<Integer> ar = new ArrayList<Integer>();
- // ar.add(1);
- // ar.size();
- }
- static void task8(){
- for (int i = 10; i > 0; i--) {
- System.out.println(i);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement