Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. Scanner in = null;
  2. in = new Scanner(System.in);
  3. String stroka;//=" ";
  4. System.out.println("Введите строки ");
  5. while(in.hasNextLine()) {
  6. int flag=0;
  7. stroka = in.nextLine();
  8. int length = stroka.length();
  9. for (int i = 0; i < length; ++i) {
  10. if((Character.isDigit(stroka.charAt(i))||stroka.charAt(i)=='.')==false)
  11. flag=0;
  12. if((Character.isDigit(stroka.charAt(i))||stroka.charAt(i)=='.')&&flag==0) {
  13. if(stroka.charAt(i)!='0') {
  14. flag=1;
  15. }
  16. if(i==length-1)
  17. break;
  18. if(stroka.charAt(i+1)=='.')
  19. flag=1;
  20. if(Character.isDigit(stroka.charAt(i+1))==false)
  21. flag=1;
  22. if(stroka.charAt(i)=='0'&&flag==0) {
  23.  
  24. stroka=stroka.substring(0,i)+stroka.substring(i+1,length);
  25. --i;
  26. --length;
  27. }
  28. }
  29.  
  30. }
  31. System.out.println(stroka);
  32. }
  33.  
  34. in.close();
  35.  
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement