Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class Main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- double age = Integer.parseInt(scan.nextLine());
- String gander = scan.nextLine();
- if (age<16) {
- if (gander.equals("m")){
- System.out.println("Master");
- } else if (gander.equals("f")){
- System.out.println("Miss");
- }
- } else if(age>=16) {
- if (gander.equals("m")){
- System.out.println("Mr.");
- } else if (gander.equals("f")){
- System.out.println("Ms.");
- }
- }
- }
- }
- 2. квартално магазинче
- package upr;
- import java.util.Scanner;
- public class homework {
- public static void main (String[] args){
- Scanner scan = new Scanner(System.in);
- String product = scan.nextLine();
- String town = scan.nextLine();
- double quantity = Double.parseDouble(scan.nextLine());
- double price = 0;
- if(town.equals("sofia")) {
- if(product.equals("coffe")) {
- 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;
- }
- }else if(town.equals("plovdiv")) {
- if (product.equals("coffe")) {
- 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;
- }
- }else if(town.equals("varna")) {
- if (product.equals("coffe")) {
- 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. плод или зеленчук
- package upr;
- import java.util.Scanner;
- public class home1 {
- 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.endsWith("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");
- }
- }
- }
- 4. Невалидно число
- package upr;
- import java.util.Scanner;
- public class hm {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- double number = scan.nextInt();
- boolean isInRange = (number >= 100 && number <= 200) || number == 0;
- if (!isInRange) {
- System.out.println("invalid");
- }
- }
- }
- 5.Магазин за плодове
- package upr;
- import java.util.Scanner;
- public class hm {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- String fruit = scan.nextLine();
- String day = scan.nextLine();
- double quantity = Double.parseDouble(scan.nextLine());
- double price = 0;
- if(day.equals("monday") || day.equals("tyesday") || day.equals("wednesday")
- || day.equals("thursday") || day.equals("friday")) {
- if (fruit.equals("banana")) {
- price = quantity * 2.5;
- }else if(fruit.equals("apple")) {
- price = quantity * 1.2;
- }else if(fruit.equals("orange")) {
- price = quantity * 0.85;
- }else if(fruit.equals("grapefruit")) {
- price = quantity * 1.45;
- }else if(fruit.equals("kiwi")) {
- price = quantity * 2.7;
- }else if(fruit.equals("pineapple")) {
- price = quantity * 5.5;
- }else if(fruit.equals("grapes")) {
- price = quantity * 3.85;
- }
- }else if(day.equals("saturday") || day.equals("sunday")) {
- if (fruit.equals("banana")) {
- price = quantity * 2.7;
- }else if(fruit.equals("apple")) {
- price = quantity * 1.25;
- }else if(fruit.equals("orange")) {
- price = quantity * 0.9;
- }else if(fruit.equals("grapefruit")) {
- price = quantity * 1.6;
- }else if(fruit.equals("kiwi")) {
- price = quantity * 3;
- }else if(fruit.equals("pineapple")) {
- price = quantity * 5.6;
- }else if(fruit.equals("grapes")) {
- price = quantity * 4.2;
- }
- }
- System.out.println(price);
- }
- }
- 6.Ден от седмицата
- package upr;
- import java.util.Scanner;
- public class hm {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int day = Integer.parseInt(scan.nextLine());
- switch (day) {
- case 1:
- System.out.println("Monday");
- break;
- case 2:
- System.out.println("Tuesday");
- break;
- case 3:
- System.out.println("Wednesday");
- break;
- case 4:
- System.out.println("Thursday");
- break;
- case 5:
- System.out.println("Friday");
- break;
- case 6:
- System.out.println("Saturday");
- break;
- case 7:
- System.out.println("Sunday");
- break;
- default:
- System.out.println("error");
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement