You are on page 1of 16

import java.io.

IOException;

import java.util.Scanner;

public class HelloStrangers {


public static void main(String[] args) throws IOException {
//Write a program, asks for a number - amount of strangers to meet.
//Then reads stranger names line by line and prints line by line
"Hello, ...".
Scanner usersInput = new Scanner(System.in);
int numberOfStrangers = usersInput.nextInt();

if (numberOfStrangers == 0) {
System.out.println("Oh, it looks like there is no one here");
} else if (numberOfStrangers < 0) {
System.out.println("Seriously? Why so negative?");
} else {
for (int i = 0; numberOfStrangers > i; i++) {
System.out.printf("Hello, %1$s\n", usersInput.nextLine());
}
}

}
}
ЩО ЗА ХУЙНЯ ЧОМУ ПОМИЛКА?

if (numberOfStrangers <= 0) {
System.out.println((numberOfStrangers == 0) ? "Oh, it looks like there is
no one here" : "Seriously? Why so negative?");
} else {
int counter = 0;
while (counter < numberOfStrangers) {
String name = usersInput.nextLine();
if (name.length() > 1) {
counter++;
System.out.printf("Hello, %1$s\n", name);
}
}
А ЦЕ ПРАЦЮЄ БЛЯДЬ ЯКОГО ХУЯ
public static void main(String[] args) {
Scanner usersDecisions = new Scanner(System.in);
int price = usersDecisions.nextInt();
int friends = usersDecisions.nextInt();
int totalAmount = (price / 10) + price;

if (friends <= 0 || totalAmount < 0) {


if (totalAmount < 0) {
System.out.println("Bill total amount cannot be negative");
} else {
System.out.println("Number of friends cannot be negative or
zero");
}
} else {
int result = totalAmount / friends;
System.out.print(result);
}
}
ПРАЦЮЄ
public static void main(String[] args) {
Scanner usersDecisions = new Scanner(System.in);
int price = usersDecisions.nextInt();
int friends = usersDecisions.nextInt();
int totalAmount = (price / 10) + price;

if (totalAmount < 0) {
System.out.println("Bill total amount cannot be negative");
}

if (friends <= 0) {
System.out.println("Number of friends cannot be negative or zero");
} else {

if (friends <= 0 && totalAmount < 0) {


int result = totalAmount / friends;
System.out.print(result);
}

НЕ ПРАЦЮЄ – ЧОМУ
public class PizzaSplit {
public static void main(String[] args) {
//Write a program, reading number of people and number of pieces per
pizza and then
//printing minimum number of pizzas to order to split all the pizzas
equally and with no remainder
Scanner usersInput = new Scanner(System.in);
int people = usersInput.nextInt();
int piecesPerPizza = usersInput.nextInt();
int savedNumberOfPieces = piecesPerPizza;
int counter = 1;

while (true) {
if (piecesPerPizza % people != 0) {
piecesPerPizza += savedNumberOfPieces;
if (counter != 1) counter++;
} else {
System.out.print(counter);
break;
}
}

WHY NOT WORKING?


public static void main(String[] args) {
Scanner usersInput = new Scanner(System.in);
int people = usersInput.nextInt();
int piecesPerPizza = usersInput.nextInt();
int savedNumberOfPieces = piecesPerPizza;
int counter = 1;

while (true) {
if (piecesPerPizza % people != 0) {
piecesPerPizza += savedNumberOfPieces;
counter++;
} else {
System.out.print(counter);
break;
}
This works, though
Result

You might also like