Created
September 14, 2015 16:12
-
-
Save Pyroarsonist/8a3a352dfcd6cce5d874 to your computer and use it in GitHub Desktop.
Есть девятиэтажный дом, в котором 4 подъезда. Номер подъезда начинается с единицы. На одном этаже 4 квартиры. Напишите программу которая получит номер квартиры с клавиатуры, и выведет на экран на каком этаже, какого подъезда расположенна эта квартира. Если такой квартиры нет в этом доме, то нужно сообщить об этом пользователю тоже.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package lvl1b; | |
| import java.util.Scanner; | |
| public class Main { | |
| public static void main(String[] args) { | |
| Scanner sc = new Scanner(System.in); | |
| int x; | |
| System.out.println("Комната: "); | |
| x=sc.nextInt(); | |
| int pod=(x-1)/36+1; //подъезд | |
| int level=(x-36*(pod-1)-1)/4+1; //этаж | |
| if (x>0&&x<145){ | |
| System.out.println("Подъезд: "+pod); | |
| System.out.println("Этаж: "+level); | |
| } | |
| else { | |
| System.out.println("ERROR!"); | |
| } | |
| sc.close(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
df