Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1.1
- import java.util.Scanner;
- public class Area {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- System.out.println("Podaj promień koła: ");
- int r = input.nextInt();
- double result = r*r*3.14;
- System.out.println("Pole koła o promieniu " +r+ " to: " +result);
- }
- }
- 1.2
- import java.util.Scanner;
- public class Division {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- System.out.println("Podaj pierwszą liczbę: ");
- double first = input.nextDouble();
- System.out.println("Podaj drugą liczbę: ");
- double second = input.nextDouble();
- double result = (first/second);
- System.out.println("Wynik dzielenia pierwszej liczby przez drugą to: " +result);
- }
- }
- 1.3
- import java.util.Scanner;
- public class Age {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- System.out.println("Podaj, ile masz lat: ");
- int age = input.nextInt();
- if (age < 18) {
- System.out.println("Nie możesz głosować");
- } else {
- if (age >= 18) {
- if (age < 35) {
- System.out.println("Możesz głosować, ale nie możesz zostać wybranym na prezydenta");
- } else
- System.out.println("Możesz kandydować na prezydenta państwa");
- }
- }
- }
- }
- 1.4
- import java.util.Scanner;
- public class Sort {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- System.out.println("Podaj pierwszą liczbę: ");
- int a = input.nextInt();
- System.out.println("Podaj drugą liczbę: ");
- int b = input.nextInt();
- System.out.println("Podaj trzecią liczbę: ");
- int c = input.nextInt();
- if (a < b) {
- if (b > c) {
- if (a < c) System.out.println("Liczby posortowane od najmniejszej: " + a + "," + c + "," + b);
- else System.out.println("Liczby posortowane od najmniejszej: " + c + "," + a + "," + b);
- } else System.out.println("Liczby posortowane od najmniejszej: " + a + "," + b + "," + c);
- } else {
- if (a > c) {
- if (b < c) System.out.println("Liczby posortowane od najmniejszej: " + b + "," + c + "," + a);
- else System.out.println("Liczby posortowane od najmniejszej: " + c + "," + b + "," + a);
- } else System.out.println("Liczby posortowane od najmniejszej: " + b +"," + a + "," + c);
- }
- }
- }
- 2.1
- public class For {
- public static void main(String[] args) {
- for (int i=1; i<=10;i++)
- System.out.println(i);
- }
- }
- 2.2
- public class For {
- public static void main(String[] args) {
- for (int i=5; i<=10;i++)
- System.out.println(i);
- }
- }
- 2.3
- public class For {
- public static void main(String[] args) {
- for (int i=10; i >=1; i--)
- System.out.println(i);
- }
- }
- 2.4 a)
- public class For {
- public static void main(String[] args) {
- for (int i=1; i <=100; i++)
- if (i % 3 == 0) System.out.println(i);
- }
- }
- 2.4 b)
- public class For {
- public static void main(String[] args) {
- for (int i=1; i <=100; i++)
- if (i % 5 == 0) System.out.println(i);
- }
- }
- 2.4 c)
- public class For {
- public static void main(String[] args) {
- for (int i=1; i <=100; i++)
- if (i % 3 == 0 && i % 5 == 0) System.out.println(i);
- }
- }
- 2.4 d)
- public class For {
- public static void main(String[] args) {
- for (int i=1; i <=100; i++)
- if (i % 3 == 0 || i % 5 == 0) System.out.println(i);
- }
- }
- 2.5
- import java.util.Scanner;
- public class For {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- System.out.println("Podaj pierwszą liczbę: ");
- int first = input.nextInt();
- System.out.println("Podaj drugą liczbę: ");
- int second = input.nextInt();
- if (first < second) {
- for (int i = first; i <= second; i++)
- System.out.println(i);
- } else {
- for (int i = second; i <= first; i++)
- System.out.println(i);
- }
- }
- }
- 2.6
- public class Multiplication {
- public static void main(String[] args) {
- for (int i = 1; i <= 10; i++) {
- for (int j = 1; j <= 10; j++) {
- System.out.printf("%5d",i*j);
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement