forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThing.java
More file actions
27 lines (26 loc) · 1.01 KB
/
Thing.java
File metadata and controls
27 lines (26 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.util.Scanner;
public class Thing {
String nameThing;
float price=-1;
void askAboutThing (){
System.out.println("Введите название товара");
Scanner scanner = new Scanner(System.in);
nameThing = scanner.next();
System.out.println("Введите стоимость товара в формате \"рубли,копейки\"");
while (true){
if (!scanner.hasNextFloat()) {
System.out.println("Введите корректную стоимость товара в формате\"рубли,копейки\"");
scanner.next();
}
else{
price = scanner.nextFloat();
if(price<=0){
System.out.println("Введите корректную стоимость товара в формате\"рубли,копейки\"");
}
else{
break;
}
}
}
}
}