Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ХИСТОГРАМА
- import java.util.Scanner;
- public class main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int n = scan.nextInt();
- double p1 = 0;
- double p2 = 0;
- double p3 = 0;
- double p4 = 0;
- double p5 = 0;
- for (int i = 0; i < n; i++) {
- int num = scan.nextInt();
- if (num < 200){
- p1++;
- }else if (num>=200 && num<400){
- p2++;
- }else if (num>=400 && num<600){
- p3++;
- }else if (num>=600 && num<800){
- p4++;
- }else if (num>=800){
- p5++;
- }
- }
- p1 = (p1/n)*100;
- p2 = (p2/n)*100;
- p3 = (p3/n)*100;
- p4 = (p4/n)*100;
- p5 = (p5/n)*100;
- System.out.printf("%.2f%%%n%.2f%%%n%.2f%%%n%.2f%%%n%.2f%%%n",p1,p2,p3,p4,p5);
- }
- }
- УМНАТА ЛИЛИ
- import java.util.Scanner;
- public class main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int years = scan.nextInt();
- double priceMachine = scan.nextDouble();
- int toyPrice = scan.nextInt();
- // int toys = 0;
- int savedMoney = 0;
- int birthdayMoney = 10;
- for (int i = 1; i <= years; i++) {
- if (i % 2 == 0) {
- savedMoney += (birthdayMoney-1);
- birthdayMoney+=10;
- }else if (i%2==1){
- savedMoney+=toyPrice;
- }
- }
- if (savedMoney >= priceMachine){
- System.out.printf("Yes! %.2f",savedMoney - priceMachine);
- }else{
- System.out.printf("No! %.2f",priceMachine-savedMoney);
- }
- }
- }
- ЗАВРЪЩАНЕ В МИНАЛОТО
- import java.util.Scanner;
- public class main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- double money = scan.nextDouble();
- int year = scan.nextInt();
- int StartYear = 1800;
- int age = 18;
- for (StartYear = 1800; StartYear <= year; StartYear++) {
- if (StartYear % 2 == 0) {
- money -= 12000;
- }
- else {
- money = money-(12000 + 50 * age);
- }
- age++;
- }
- if(money>=0) {
- System.out.printf("Yes! He will live a carefree life and will have %.2f dollars left.",money);
- }else {
- money =Math.abs(money);
- System.out.printf("He will need %.2f dollars to survive.",money);
- }
- }
- }
- БОЛНИЦА
- import java.util.Scanner;
- public class main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int days = scan.nextInt();
- int treated = 0;
- int untreated = 0;
- int doctors = 7;
- for (int i = 1; i <= days; i++) {
- int patients = scan.nextInt();
- if (i%3==0 && (untreated>treated)){
- doctors++;
- }
- if (patients>doctors){
- treated+=doctors;
- untreated += patients-doctors;
- }else {
- treated += patients;
- }
- }
- System.out.println("Treated patients: "+treated+".");
- System.out.println("Untreated patients: "+untreated+".");
- }
- }
- ДЕЛЕНИЕ БЕЗ ОСТАТЪК
- import java.util.Scanner;
- public class main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int n = scan.nextInt();
- double p1 = 0;
- double p2 = 0;
- double p3 = 0;
- for (int i = 0; i < n ; i++) {
- int num = scan.nextInt();
- if(num%2 == 0){
- p1++;
- }
- if(num%3 == 0){
- p2++;
- }
- if(num%4 == 0){
- p3++;
- }
- }
- p1 = (p1/n)*100;
- p2 = (p2/n)*100;
- p3 = (p3/n)*100;
- System.out.printf("%.2f%% %n",p1);
- System.out.printf("%.2f%% %n",p2);
- System.out.printf("%.2f%% %n",p3);
- }
- }
- ЛОГИСТИКА
- import java.util.Scanner;
- public class main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int count = scan.nextInt();
- double busTons = 0;
- double truckTons = 0;
- double trainTons = 0;
- double price = 0;
- int allTons= 0;
- for (int i = 0; i < count; i++) {
- int tons = scan.nextInt();
- allTons+=tons;
- if (tons<=3){
- busTons+=tons;
- }else if(tons > 3 && tons<=11){
- truckTons+=tons;
- }else if(tons > 11){
- trainTons+=tons;
- }
- }
- price = (busTons*200 +truckTons*175+trainTons*120)/allTons;
- busTons = (busTons/allTons)*100;
- truckTons = (truckTons/allTons)*100;
- trainTons = (trainTons/allTons)*100;
- System.out.printf("%.2f%n",price);
- System.out.printf("%.2f%%%n",busTons);
- System.out.printf("%.2f%%%n",truckTons);
- System.out.printf("%.2f%%",trainTons);
- }
- }
Add Comment
Please, Sign In to add comment