Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Homework: Introduction to Java/////////////////////////////////////////////////////////
- 5 zadacha
- LocalDateTime today = LocalDateTime.now();
- System.out.println("Today is: " + today);
- LocalDateTime tomorrow = today.plusDays(1);
- System.out.println("Tomorrow will be: " + tomorrow);
- 6 zadacha
- Scanner input = new Scanner(System.in);
- int numa = input.nextInt();
- Scanner input1 = new Scanner(System.in);
- int numb = input1.nextInt();
- int sum = numa + numb;
- System.out.println(sum);
- 8 zadacha
- Scanner scanner = new Scanner(System.in);
- int n = scanner.nextInt();
- scanner.nextLine();
- String[] lines = new String[n];
- for (int i = 0; i < n; i++) {
- lines[i] = scanner.nextLine();
- }
- // Sort the array of strings
- Arrays.sort(lines);
- System.out.println();
- System.out.println();
- // Print the sorted array
- for (int i = 0; i < lines.length; i++) {
- System.out.println(lines[i]);
- }
- Homework: Java Syntax////////////////////////////////////////////////////////////////////////////////////
- Problem 1. Rectangle Area
- Scanner input = new Scanner(System.in);
- System.out.printf("pravougulnik- visochina = ",input);
- int numa = input.nextInt();
- Scanner input1 = new Scanner(System.in);
- System.out.printf("pravougulnik- duljina = ",input1);
- int numb = input1.nextInt();
- int sum = numa * numb;
- System.out.printf("pravougulnik area = " + sum);
- Problem 2. Triangle Area
- Scanner input = new Scanner(System.in);
- int ax = input.nextInt();
- Scanner input1 = new Scanner(System.in);
- int ay = input1.nextInt();
- Scanner input2 = new Scanner(System.in);
- int bx = input.nextInt();
- Scanner input3 = new Scanner(System.in);
- int by = input1.nextInt();
- Scanner input4 = new Scanner(System.in);
- int cx = input.nextInt();
- Scanner input5 = new Scanner(System.in);
- int cy = input1.nextInt();
- double a = Math.sqrt(Math.pow((cx - bx),2)+Math.pow((cy - by),2));
- double b = Math.sqrt(Math.pow((cx - ax),2)+Math.pow((cy - ay),2));
- double c = Math.sqrt(Math.pow((bx - ax),2)+Math.pow((by - ay),2));
- if(a + c > c && a + c > b && b + c > a)
- {
- double p = (a + b + c) / 2;
- double area = Math.sqrt(p*(p-a)*(p-b)*(p-c));
- area = Math.round(area);
- System.out.println("Yes");
- System.out.println((int)area);
- }
- else
- {
- System.out.println("No");
- c = Math.round(c,2); // tova e dr variant da zakruglqm do 2 znam ako napisha 3 she go zakrugli do 3 znak
- System.out.printf("{0:0.00}", c);
- }
- }
- problem 3 points inside figure
- // Scanner input = new Scanner(System.in);
- // int h = input.nextInt();
- // double h = 2.5;
- for (int i = 0; i < 10; i++)
- {
- //////// X
- Scanner input1 = new Scanner(System.in);
- double x = input1.nextDouble();
- ///////// Y
- Scanner input2 = new Scanner(System.in);
- double y = input2.nextDouble();
- boolean box1 = ((x >= 12.5 && x <= 22.5) && (y >= 6 && y <= 8.5));
- boolean box2 = ((x >= 12.5 && x <= 17.5) && (y >= 8.5 && y <= 13.5));
- boolean box3 = ((x >= 20.0 && x <= 22.5) && (y >= 8.5 && y <= 13.5));
- if (box1 || box2 || box3)// moje i s if 1 zadachi C# 8 variant
- {
- System.out.println("inside");
- }
- else
- {
- System.out.println("outside");
- }
- }
- Problem 4. The Smallest of 3 Numbers
- Scanner input = new Scanner(System.in);
- System.out.printf("A ",input);
- double numa = input.nextDouble();
- Scanner input1 = new Scanner(System.in);
- System.out.printf("B ",input1);
- double numb = input1.nextDouble();
- Scanner input2 = new Scanner(System.in);
- System.out.printf("C ",input1);
- double numc = input2.nextDouble();
- double Smallest = 0;
- if(numa > numb){
- Smallest = numb;
- }
- else {
- Smallest = numa;
- }
- if(numc < Smallest){
- Smallest = numc;
- }
- System.out.printf("Smallest " + Smallest);
- problem 9 .Points inside the House
- for (int i =0; i <= 20; i++){
- ///////////// x
- Scanner input = new Scanner(System.in);
- double x = input.nextDouble();
- ////////////// y
- Scanner input1 = new Scanner(System.in);
- double y = input1.nextDouble();
- double x1 = 12.5;
- double x2 = 17.5;
- double x3 = 22.5;
- double y1 = 8.5;
- double y2 = 3.5;
- double y3 = 8.5;
- //////////////////////////////////
- double ABC = Math.abs (x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2));
- double ABP = Math.abs (x1 * (y2 - y) + x2 * (y - y1) + x * (y1 - y2));
- double APC = Math.abs (x1 * (y - y3) + x * (y3 - y1) + x3 * (y1 - y));
- double PBC = Math.abs (x * (y2 - y3) + x2 * (y3 - y) + x3 * (y - y2));
- ///// triugulnik
- boolean isInTriangle = ABP + APC + PBC == ABC;
- ///////// kvadrati
- boolean box1 = ((x >= 12.5 && x <= 17.5) && (y >= 8.5 && y <= 13.5));
- boolean box2 = ((x >= 20.0 && x <= 22.5) && (y >= 8.5 && y <= 13.5));
- if (isInTriangle || box1 || box2)
- {
- System.out.println("inside");
- }
- else
- {
- System.out.println("outside");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement