Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1зад. "Обръщение според възраст и пол":
- import java.util.Scanner;
- class Main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- String gander = scan.nextLine();
- int age = scan.nextInt();
- if (age<16) {
- if (gander.equals("male")){
- System.out.println("Master");
- } else if (gander.equals("female")){
- System.out.println("Miss");
- }
- } else if(age>=16) {
- if (gander.equals("male")){
- System.out.println("Ms.");
- } else if (gander.equals("female")){
- System.out.println("Mr.");
- }
- }
- }
- }
- 2зад. "Квартално магазинче":
- import java.util.Scanner;
- class Main {
- public static void main(String[] args) {
- String product = scan.nextLine() .toLowerCase();
- String town = scan.nextLine() .toLowerCase();
- double quantity = Double.parseDouble(scan.nextLine());
- double price = 0;
- if (town.equals("sofia")){
- if(product.equals("coffee")){
- price = quantity * 0.5;
- } else if(product.equals("water")){
- price = quantity * 0.8;
- } else if(product.equals("beer")){
- price = quantity * 1.2;
- } else if(product.equals("sweets")){
- price = quantity * 1.45;
- } else if(product.equals("peanuts")){
- price = quantity * 1.6;
- }
- }
- if (town.equals("plovdiv")){
- if(product.equals("coffee")){
- price = quantity * 0.4;
- } else if(product.equals("water")){
- price = quantity * 0.7;
- } else if(product.equals("beer")){
- price = quantity * 1.15;
- } else if(product.equals("sweets")){
- price = quantity * 1.3;
- } else if(product.equals("peanuts")){
- price = quantity * 1.5;
- }
- }
- if (town.equals("varna")){
- if(product.equals("coffee")){
- price = quantity * 0.45;
- } else if(product.equals("water")){
- price = quantity * 0.7;
- } else if(product.equals("beer")){
- price = quantity * 1.1;
- } else if(product.equals("sweets")){
- price = quantity * 1.35;
- } else if(product.equals("peanuts")){
- price = quantity * 1.55;
- }
- }
- System.out.println(price);
- }
- }
- 3зад. "Точка в правоъгълник":
- import java.util.Scanner;
- class Main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- double x1 = Double.parseDouble(scan.nextLine());
- double y1 = Double.parseDouble(scan.nextLine());
- double x2 = Double.parseDouble(scan.nextLine());
- double y2 = Double.parseDouble(scan.nextLine());
- double x = Double.parseDouble(scan.nextLine());
- double y = Double.parseDouble(scan.nextLine());
- if ((x >= x1 && x <= x2) && (y >= y1 && y <= y2)){
- System.out.println("Inside");
- } else {
- System.out.println("Outside");
- }
- }
- }
- 4зад. "Плод или зеленчук":
- import java.util.Scanner;
- class Main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- String product = scan.nextLine();
- boolean isFruit = product.equals("banana") || product.equals("apple") || product.equals("kiwi") || product.equals("cherry") || product.equals("lemon") || product.equals("grapes");
- boolean isVegetable = product.equals("tomato") || product.equals("cucumber") || product.equals("pepper") || product.equals("carrot");
- if (isFruit) {
- System.out.println("fruit");
- } else if (isVegetable) {
- System.out.println("vegetable");
- } else {
- System.out.println("unknown");
- }
- }
- }
- 5зад. "Невалидно число":
- import java.util.Scanner;
- class Main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- double number = Double.parseDouble(scan.nextLine());
- boolean diapazon = (number >= 100 && number <= 200) || number == 0;
- if (!diapazon) {
- System.out.println("invalid");
- }
- }
- }
- 6зад. "Точка върху страна на триъгълник":
- import java.util.Scanner;
- class Main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- double x1 = Double.parseDouble(scan.nextLine());
- double y1 = Double.parseDouble(scan.nextLine());
- double x2 = Double.parseDouble(scan.nextLine());
- double y2 = Double.parseDouble(scan.nextLine());
- double x = Double.parseDouble(scan.nextLine());
- double y = Double.parseDouble(scan.nextLine());
- if (((x==x1) || (x==x2)) && (y>=y1) && (y<=y2)){
- System.out.println("Border");
- } else if (((y==y1) || (y==y2)) && (x>=x1) && (x<=x2)){
- System.out.println("Border");
- } else {
- System.out.println("Inside/outside");
- }
- }
- }
- 7зад. "Магазин за плодове":
- import java.util.Scanner;
- class Main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- String plod = scan.nextLine();
- String day = scan.nextLine();
- String quantity = scan.nextLine();
- String price = scan.nextLine();
- if (day.equals("monday")) || (day.equals("tuesday")) || (day.equals("wednes")) || (day.equals("thurday")) || (day.equals("friday")){
- if (fruit.equals("banana")){
- price = quantity * 2.50;
- } if (fruit.equals("apple")){
- price = quantity * 1.20;
- } if (fruit.equals("orange")){
- price = quantity * 0.80;
- }
- } else if (day.equals("saturday")) || (day.equals("sunday")){
- if (fruit.equals("banana")){
- price = quantity * 2.70;
- } if (fruit.equals("apple")){
- price = quantity * 1.25;
- } if (fruit.equals("orange")){
- price = quantity * 0.90;
- }
- }
- System.out.println(price);
- }
- }
- 11зад. "Кено":
- import java.util.Scanner;
- class Main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- String type = scan.nextLine();
- int redove = Integer.parseInt(scan.nextLine());
- int coloni = Integer.parseInt(scan.nextLine());
- int mesta = redove * coloni;
- double dohodi = 0;
- switch (type){
- case "premiere": dohodi = mesta * 12; break;
- case "normal": dohodi = mesta * 7.50; break;
- case "discount": dohodi = mesta * 5; break;
- }
- System.out.println(dohodi);
- }
- }
Add Comment
Please, Sign In to add comment