biryu2205 / Biryu

0 stars 0 forks source link

Solve all problems in the given link #66

Closed letientai299 closed 7 years ago

letientai299 commented 7 years ago

http://www.w3resource.com/java-exercises/basic/index.php

For each problem, post your solution as a comment here.

Check list:

biryu2205 commented 7 years ago

1.

public class Test {
  public static void main(String[] args) {
    System.out.print("Hello \n"+"Alexandra Abramov");
  }
}
letientai299 commented 7 years ago

Your name, not their name. But this solution is ok, anyways.

biryu2205 commented 7 years ago

2.

import java.util.Scanner;

public class Test {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    System.out.println("Please Insert 1st Number");
    int a = sc.nextInt();
    System.out.println("Please Insert 2nd Number");
    int b = sc.nextInt();
    System.out.println(a + b);
  }
}
biryu2205 commented 7 years ago

3.

import java.util.Scanner;

public class Test {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    System.out.println("Please Insert 1st Number");
    int a = sc.nextInt();
    System.out.println("Please Insert 2nd Number");
    int b = sc.nextInt();
    System.out.println(a / b);
  }
}
biryu2205 commented 7 years ago

4.

public class Test {
  public static void main(String[] args) {
    System.out.println(-5+8*6);
    System.out.println((55+9) % 9 );
    System.out.println(20 + -3*5 / 8);
    System.out.println(5 + 15 / 3 * 2 - 8 % 3);
  }
}
biryu2205 commented 7 years ago

5.

import java.util.Scanner;

public class Test {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    System.out.println("Please Insert 1st Number");
    int a = sc.nextInt();
    System.out.println("Please Insert 2nd Number");
    int b = sc.nextInt();
    System.out.println(a + " * " + b + " = " + a * b);
  }
}
letientai299 commented 7 years ago

Please optimize your usage of printf in the ex-5

biryu2205 commented 7 years ago

6.

import java.util.Scanner;

public class Test {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    System.out.println("Please Insert 1st Number");
    int a = sc.nextInt();
    System.out.println("Please Insert 2nd Number");
    int b = sc.nextInt();
    System.out.println(a + " + " + b + " = " + a + b);
    System.out.println(a + " - " + b + " = " + a - b);
    System.out.println(a + " * " + b + " = " + a * b);
    System.out.println(a + " / " + b + " = " + a / b);
    System.out.println(a + " mod " + b + " = " + a % b);
  }
}
biryu2205 commented 7 years ago

7

import java.util.Scanner;

public class Test {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    System.out.println("Please Insert a Number");
    int number = sc.nextInt();
    for (int i = 0; i <= 10; i++) {
      System.out.println(number + "*" + i + " = " + number * i);
    }
  }
}
biryu2205 commented 7 years ago

8.

public class Test {
  public static void main(String[] args) {
    System.out.println("   J    a   v     v  a ");
    System.out.println("   J   a a   v   v  a a");
    System.out.println("J  J  aaaaa   V V  aaaaa");
    System.out.println(" JJ  a     a   V  a     a");
    }
  }
biryu2205 commented 7 years ago

9.

public class Test {
  public static void main(String[] args) {
    System.out.println((25.5 * 3.5 - 3.5 * 3.5) / (40.5 - 4.5));
    }
  }
biryu2205 commented 7 years ago

10.

public class Test {
  public static void main(String[] args) {
    System.out.println((4.0 * (1 - (1.0/3) + (1.0/5) - (1.0/7) + (1.0/9) - (1.0/11))));
    }
  }
biryu2205 commented 7 years ago

11.

import java.util.Scanner;

public class Test {
  public static void main(String[] args) {
    System.out.println("Please Insert Radius Of Circle");
    Scanner sc = new Scanner(System.in);
    float radius = sc.nextFloat();
    System.out.println("Perimeter is = " + radius * 2 * Math.PI);
    System.out.println("Area is = " + radius * radius * Math.PI);
  }
}
letientai299 commented 7 years ago

Wrong exercie order. Your 12th solution should belong to ex 11. And your 11th solution is incomplete.

biryu2205 commented 7 years ago

wrong copy ,sorry -_-

biryu2205 commented 7 years ago

13.

import java.util.Scanner;

public class Test {
  public static void main(String[] args) {
    System.out.println("Please Insert Width");
    Scanner sc = new Scanner(System.in);
    float Width = sc.nextFloat();
    System.out.println("Please Insert Height");
    float Height = sc.nextFloat();
    System.out.println("Perimeter Of Rectangle = " + (Width + Height) / 2);
    System.out.println("Area Of Rectangle = " + Width * Height);
  }
}
biryu2205 commented 7 years ago

12.

import java.util.Scanner;

public class Test {
  public static void main(String[] args) {
    System.out.println("Please Insert 1st Number");
    Scanner sc = new Scanner(System.in);
    double number1 = sc.nextFloat();
    System.out.println("Please Insert 2nd Number");
    double number2 = sc.nextFloat();
    System.out.println("Please Insert 3rd Number");
    double number3 = sc.nextFloat();
    System.out.println("Average Of The Numbers : " + (number1 + number2 + number3) / 3);
  }
}
biryu2205 commented 7 years ago

14.

import java.util.Scanner;

public class Test {
  public static void main(String[] args) {
    System.out.println("* * * * * * ==================================");
    System.out.println(" * * * * *  ==================================");
    System.out.println("* * * * * * ==================================");
    System.out.println(" * * * * *  ==================================");
    System.out.println("* * * * * * ==================================");
    System.out.println(" * * * * *  ==================================");
    System.out.println("* * * * * * ==================================");
    System.out.println(" * * * * *  ==================================");
    System.out.println("* * * * * * ==================================");
    System.out.println("==============================================");
    System.out.println("==============================================");
    System.out.println("==============================================");
    System.out.println("==============================================");
    System.out.println("==============================================");
    System.out.println("==============================================");
  }
}
biryu2205 commented 7 years ago

15.

import java.util.Scanner;

public class Test {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    System.out.println("Please Insert 1st Number");
    int number1 = sc.nextInt();
    System.out.println("Please Insert 2nd Number");
    int number2 = sc.nextInt();
    int swap=0;
    System.out.println("1st and 2nd Number before swap "+number1+" , "+number2);
    swap=number1;
    number1=number2;
    number2=swap;
    System.out.println("1st and 2nd Number after swap "+number1+" , "+number2);
  }
}
biryu2205 commented 7 years ago

16.

public class Test {
  public static void main(String[] args) {
    System.out.println(" +\"\"\"\"\"+ ");
    System.out.println("[| o o |]");
    System.out.println(" |  ^  | ");
    System.out.println(" | '-' | ");
    System.out.println(" +-----+ ");
  }
}
biryu2205 commented 7 years ago

17.

import java.util.Scanner;

import static java.lang.Integer.parseInt;

public class Test {

  public static void main(String[] args) {
    System.out.println("Please Insert 1st Binary Number");
    Scanner sc = new Scanner(System.in);
    String number1 = sc.nextLine();
    System.out.println("Please Insert 2nd Binary ");
    String number2 = sc.nextLine();
    int sum = parseInt(number1, 2) + parseInt(number2, 2);
    String sumbinary = Integer.toBinaryString(sum);
    System.out.println(sumbinary);
  }
}
biryu2205 commented 7 years ago

18.

import java.util.Scanner;

import static java.lang.Integer.parseInt;

public class Test {

  public static void main(String[] args) {
    System.out.println("Please Insert 1st Binary Number");
    Scanner sc = new Scanner(System.in);
    String number1 = sc.nextLine();
    System.out.println("Please Insert 2nd Binary ");
    String number2 = sc.nextLine();
    int sum = parseInt(number1, 2) * parseInt(number2, 2);
    String sumbinary = Integer.toBinaryString(sum);
    System.out.println(sumbinary);
  }
}
biryu2205 commented 7 years ago

19.

public static void main(String[] args) {
    System.out.println("Please Insert Int Number");
    Scanner sc = new Scanner(System.in);
    int number = sc.nextInt();
    System.out.println(Integer.toBinaryString(number));
  }
letientai299 commented 7 years ago

17, 18, 19. Do you know that there's a function Integer.parseInt(String s, int radix).

biryu2205 commented 7 years ago

Thanks for your help,i ll try it.

biryu2205 commented 7 years ago

20.

import java.util.Scanner;
import static java.lang.Integer.toHexString;

public class Test {

  public static void main(String[] args) {
    System.out.println("Please Insert int Number");
    Scanner sc = new Scanner(System.in);
    int number = sc.nextInt();
    System.out.println(toHexString(number));
  }
}
biryu2205 commented 7 years ago

21

import java.util.Scanner;
import static java.lang.Integer.toOctalString;

public class Test {

  public static void main(String[] args) {
    System.out.println("Please Insert int Number");
    Scanner sc = new Scanner(System.in);
    int number = sc.nextInt();
    System.out.println(toOctalString(number));
  }
}
biryu2205 commented 7 years ago

22.

import java.util.Scanner;
import static java.lang.Integer.parseInt;

public class Test {

  public static void main(String[] args) {
    System.out.println("Please Insert Binary Number");
    Scanner sc = new Scanner(System.in);
    int number = sc.nextInt();
   number= parseInt(Integer.toString(number),2);
    System.out.println(number);
  }
}
biryu2205 commented 7 years ago

23.

import java.util.Scanner;
import static java.lang.Integer.parseInt;
import static java.lang.Integer.toHexString;

public class Test {

  public static void main(String[] args) {
    System.out.println("Please Insert Binary Number");
    Scanner sc = new Scanner(System.in);
    int number = sc.nextInt();
    Integer.toString(number);
    number = parseInt(Integer.toString(number), 2);
    System.out.println(toHexString(number));
  }
}
biryu2205 commented 7 years ago

24.

import java.util.Scanner;
import static java.lang.Integer.parseInt;
import static java.lang.Integer.toOctalString;

public class Test {
  public static void main(String[] args) {
    System.out.println("Please Insert Binary Number");
    Scanner sc = new Scanner(System.in);
    int number = sc.nextInt();
    Integer.toString(number);
    number = parseInt(Integer.toString(number), 2);
    System.out.println(toOctalString(number));
  }
}
biryu2205 commented 7 years ago

25.

import java.util.Scanner;
import static java.lang.Integer.parseInt;

public class Test {

  public static void main(String[] args) {
    System.out.println("Please Insert Octal Number");
    Scanner sc = new Scanner(System.in);
    int number = sc.nextInt();
    Integer.toString(number);
    number = parseInt(Integer.toString(number), 8);
    System.out.println(number);
  }
}
biryu2205 commented 7 years ago

26.

import java.util.Scanner;

import static java.lang.Integer.parseInt;
import static java.lang.Integer.toBinaryString;

public class Test {

  public static void main(String[] args) {
    System.out.println("Please Insert Octal Number");
    Scanner sc = new Scanner(System.in);
    int number = sc.nextInt();
    Integer.toString(number);
    number = parseInt(Integer.toString(number), 8);
    System.out.println(toBinaryString(number));
  }
}
biryu2205 commented 7 years ago

27.

import java.util.Scanner;

import static java.lang.Integer.parseInt;
import static java.lang.Integer.toHexString;

public class Test {

  public static void main(String[] args) {
    System.out.println("Please Insert Octal Number");
    Scanner sc = new Scanner(System.in);
    int number = sc.nextInt();
    Integer.toString(number);
    number = parseInt(Integer.toString(number), 8);
    System.out.println(toHexString(number));
  }
}
biryu2205 commented 7 years ago

28.

import java.util.Scanner;

import static java.lang.Integer.parseInt;

public class Test {

  public static void main(String[] args) {
    System.out.println("Please Insert Hexadecximal Number");
    Scanner sc = new Scanner(System.in);
    int number = sc.nextInt();
    Integer.toString(number);
    number = parseInt(Integer.toString(number), 16);
    System.out.println(number);
  }
}
biryu2205 commented 7 years ago

29.

import java.util.Scanner;

import static java.lang.Integer.parseInt;
import static java.lang.Integer.toBinaryString;

public class Test {

  public static void main(String[] args) {
    System.out.println("Please Insert Hexadecximal Number");
    Scanner sc = new Scanner(System.in);
    int number = sc.nextInt();
    Integer.toString(number);
    number = parseInt(Integer.toString(number), 16);
    System.out.println(toBinaryString(number));
  }
}
biryu2205 commented 7 years ago

30.

import java.util.Scanner;

import static java.lang.Integer.parseInt;
import static java.lang.Integer.toOctalString;

public class Test {

  public static void main(String[] args) {
    System.out.println("Please Insert Hexadecximal Number");
    Scanner sc = new Scanner(System.in);
    int number = sc.nextInt();
    Integer.toString(number);
    number = parseInt(Integer.toString(number), 16);
    System.out.println(toOctalString(number));
  }
}
biryu2205 commented 7 years ago

31.

public class Test {

  public static void main(String[] args) {
    System.out.println("\nJava Version: " + System.getProperty("java.version"));
    System.out.println("Java Runtime Version: " + System.getProperty("java.runtime.version"));
    System.out.println("Java Home: " + System.getProperty("java.home"));
    System.out.println("Java Vendor: " + System.getProperty("java.vendor"));
    System.out.println("Java Vendor URL: " + System.getProperty("java.vendor.url"));
    System.out.println("Java Class Path: " + System.getProperty("java.class.path") + "\n");
  }
}
biryu2205 commented 7 years ago

32.

import java.util.Scanner;

public class Test {

  public static void main(String[] args) {
    System.out.println("Please Insert 1st Number");
    Scanner sc = new Scanner(System.in);
    int number1 = sc.nextInt();
    System.out.println("Please Insert 2nd Number ");
    int number2 = sc.nextInt();
    if (number1 == number2) {
      System.out.println(number1 + " = " + number2);
    } else {
      System.out.println(number1 + " != " + number2);
    }
    if (number1 > number2) {
      System.out.println(number1 + " > " + number2);
      System.out.println(number1 + " >= " + number2);
    }
    if (number1 < number2) {
      System.out.println(number1 + " < " + number2);
      System.out.println(number1 + " <= " + number2);
    }
  }
}
biryu2205 commented 7 years ago

33.

import java.util.Scanner;

public class Test {

  public static void main(String[] args) {
    System.out.println("Please Insert  Number");
    Scanner sc = new Scanner(System.in);
    int number = sc.nextInt();
    int sum = 0;
    while (number > 0) {
      sum = sum + number % 10;
      number = number / 10;
    }
    System.out.println("The sum of the digits is: "+sum);
  }
}
biryu2205 commented 7 years ago

34.

import java.util.Scanner;

public class Test {

  public static void main(String[] args) {
    System.out.println("Please Input the length of a side of the hexagon");
    Scanner sc = new Scanner(System.in);
    double number = sc.nextDouble();
    System.out.println(
        "The area of the hexagon is: " + (6 * number * number) / (4 * Math.tan(Math.PI / 6)));
  }
}
biryu2205 commented 7 years ago

35.

import java.util.Scanner;

public class Test {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    System.out.println("Please Input the number of sides on the polygon: ");
    double numberSide = sc.nextDouble();
    System.out.println("Please Input the length of one of the sides: ");
    double numberLenght = sc.nextDouble();
    System.out.println(
        "The area is : " + (numberSide * numberLenght * numberLenght) / (4 * Math.tan(
            Math.PI / numberSide)));
  }
}
biryu2205 commented 7 years ago

36.

import java.util.Scanner;

public class Test {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    double lat1, lat2, long1, long2;
    System.out.println("Input the latitude of coordinate 1 :");
    double latitude1 = sc.nextDouble();
    lat1 = Math.toRadians(latitude1);
    System.out.println("Input the longitude of coordinate 1");
    double longitude1 = sc.nextDouble();
    long1 = Math.toRadians(longitude1);
    System.out.println("Input the latitude of coordinate 2 :");
    double latitude2 = sc.nextDouble();
    lat2 = Math.toRadians(latitude2);
    System.out.println("Input the latitude of coordinate 2 :");
    double longitude2 = sc.nextDouble();
    long2 = Math.toRadians(longitude2);
    double d = 6371.01 * Math.acos(
        Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos(
            long1 - long2));
    System.out.println(
        "The distance between those points is:" + d);
  }
}
biryu2205 commented 7 years ago

38.

import java.util.Scanner;

public class Test {

  public static void main(String[] args) {
    System.out.println("Please Input a String");
    Scanner sc = new Scanner(System.in);
    String text = sc.nextLine();
    char[] textArray = text.toCharArray();
    int letter = 0;
    int space = 0;
    int num = 0;
    int other = 0;
    for (int i = 0; i < text.length(); i++) {
      if (Character.isLetter(textArray[i])) {
        letter++;
      } else if (Character.isDigit(textArray[i])) {
        num++;
      } else if (Character.isSpaceChar(textArray[i])) {
        space++;
      } else {
        other++;
      }
    }
    System.out.println("The string is : " +text);
    System.out.println("letter: " + letter);
    System.out.println("space: " + space);
    System.out.println("number: " + num);
    System.out.println("other: " + other);
  }
}
biryu2205 commented 7 years ago

I'm on my way.

biryu2205 commented 7 years ago

37.

import java.util.Scanner;

public class Test {

  public static void main(String[] args) {
    System.out.println("Please Input a String");
    Scanner sc = new Scanner(System.in);
    String text = sc.nextLine();
    char[] textArray = text.toCharArray();
    System.out.println("Reverse string: ");
    for (int i = textArray.length - 1; i >= 0; i--) {
      System.out.print(textArray[i]);
    }
  }
}
biryu2205 commented 7 years ago

39.

public class Test {

  public static void main(String[] args) {

    int count = 0;
    for (int i = 1; i <= 4; i++) {
      for (int j = 1; j <= 4; j++) {
        for (int k = 1; k <= 4; k++) {
          if (k != i && k != j && i != j) {
            count++;
            System.out.println(i + "" + j + "" + k);
          }
        }
      }
    }
    System.out.println("Total number of the three-digit-number is " + count);
  }
}
biryu2205 commented 7 years ago

40.

import java.nio.charset.Charset;

public class Test {

  public static void main(String[] args) {

    System.out.println("List of available character sets: ");
    for (String result : Charset.availableCharsets().keySet()) {
      System.out.println(result);
    }
  }
}
biryu2205 commented 7 years ago

43.

public class Test {

  public static void main(String[] args) {

    System.out.println("Twinkle, twinkle, little star,\n"
        + "\tHow I wonder what you are! \n"
        + "\t\tUp above the world so high,   \t\t\n"
        + "\t\tLike a diamond in the sky. \n"
        + "Twinkle, twinkle, little star, \n"
        + "\tHow I wonder what you are\n");
  }
}
biryu2205 commented 7 years ago

41.

public class Test {
  public static void main(String[] String) {
    int chr = 'Z';
    System.out.println("The ASCII value of Z is :" + chr);
  }
}
biryu2205 commented 7 years ago

44.

import java.util.Scanner;

public class Test {
  public static void main(String[] String) {
    System.out.println("Please Insert N");
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    System.out.printf("%d + %d%d + %d%d%d ", n, n, n, n, n, n);
  }
}