Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 2ra . package com.company;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int number = Integer.parseInt(scanner.nextLine());
- if (number % 10 == 0) {
- System.out.println("The number is divisible by 10");
- } else if (number % 7 == 0) {
- System.out.println("The number is divisible by 7");
- } else if (number % 6 == 0) {
- System.out.println("The number is divisible by 6");
- } else if (number % 3 == 0) {
- System.out.println("The number is divisible by 3");
- } else if (number % 2 == 0) {
- System.out.println("The number is divisible by 2");
- }
- else{
- System.out.println("Not divisible");
- }
- }
- }
- 3.ta import java.util.Scanner;
- public class JF_3_Vacation {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int peopleNum = Integer.parseInt(scanner.nextLine());
- String typePeople = scanner.nextLine();
- String day = scanner.nextLine();
- double price = 0;
- switch (typePeople) {
- case "Students":
- if ("Friday".equals(day)) {
- price = 8.45;
- } else if ("Saturday".equals(day)) {
- price = 9.80;
- } else if ("Sunday".equals(day)) {
- price = 10.46;
- }
- break;
- case "Business":
- if ("Friday".equals(day)) {
- price = 10.90;
- } else if ("Saturday".equals(day)) {
- price = 15.60;
- } else if ("Sunday".equals(day)) {
- price = 16;
- }
- break;
- case "Regular":
- if ("Friday".equals(day)) {
- price = 15;
- } else if ("Saturday".equals(day)) {
- price = 20.00;
- } else if ("Sunday".equals(day)) {
- price = 22.50;
- }
- break;
- }
- double subTotal = peopleNum * price;
- if ("Students".equals(typePeople) && peopleNum >= 30) {
- subTotal *= 0.85;
- }
- else if ("Business".equals(typePeople) && peopleNum >= 100) {
- subTotal = (peopleNum - 10) * price; }
- else if ("Regular".equals(typePeople) && peopleNum >= 10 && peopleNum <= 20) {
- subTotal *= 0.95;
- }
- System.out.printf("Total price: %.2f", subTotal);
- }
- }
- 4ta . package com.company;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int startNumber = Integer.parseInt(scanner.nextLine());
- int endNumber = Integer.parseInt(scanner.nextLine());
- int sum =0;
- for (int i = startNumber; i <= endNumber; i++) {
- System.out.print(i + " ");
- sum +=i;
- }
- System.out.printf("%nSum: %d",sum);
- }
- }
- 5ta import java.util.Scanner;
- public class Login {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String username = scanner.nextLine();
- String password = "";
- int count = 0;
- for (int i = username.length() - 1; i >= 0; i--) {
- password += username.charAt(i);
- }
- String input = scanner.nextLine();
- while (!input.equals(password)) {
- count++;
- if (count == 4) {
- System.out.printf("User %s blocked!", username);
- return;
- }
- System.out.println("Incorrect password. Try again.");
- input = scanner.nextLine();
- }
- System.out.printf("User %s logged in.", username);
- }
- }
- 6ta package com.company;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String input = scanner.nextLine();
- int totalSum = 0;
- for (int i = 0; i < input.length(); i++) {
- int digit = Integer.parseInt("" +input.charAt(i));
- int currentSum = 1;
- for (int j = digit; j>=1 ; j--) {
- currentSum *= j;
- }
- totalSum+=currentSum;
- }
- int number = Integer.parseInt(input);
- if(number == totalSum){
- System.out.println("yes");
- }else{
- System.out.println("no");
- }
- }
- }
- 7ma import java.util.Scanner;
- public class VendingMachine {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double sum = 0;
- int total = 0;
- String textInput = "";
- while (true) {
- textInput = scanner.nextLine();
- if (textInput.equals("Start")) {
- break;
- }
- double coin = Double.parseDouble(textInput);
- if (coin == 0.1 || coin == 0.2 || coin == 0.5 || coin == 1 || coin == 2) {
- sum += coin;
- } else {
- System.out.println("Cannot accept " + coin);
- }
- }
- double price = 0;
- String input ;
- boolean flag = false;
- while (true) {
- input = scanner.nextLine();
- switch (input.toLowerCase()) {
- case "nuts":
- price = 2;
- flag = true;
- break;
- case "water":
- price = 0.7;
- flag = true;
- break;
- case "crisps":
- price = 1.5;
- flag = true;
- break;
- case "soda":
- price = 0.8;
- flag = true;
- break;
- case "coke":
- price = 1;
- flag = true;
- break;
- }
- if (input.equals("End")) {
- break;
- }
- if (sum < price) {
- System.out.println("Sorry, not enough money");
- } else if (flag) {
- System.out.println("Purchased " + input);
- sum -= price;
- } else {
- System.out.println("Invalid product");
- }
- }
- System.out.printf("Change: %.2f", sum);
- }
- }
- 8ma package com.company;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- for (int i = 1; i <=n ; i++) {
- for (int j = 0; j < i; j++) {
- System.out.print(i + " ");
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement