-
-
Save rangalo/543617 to your computer and use it in GitHub Desktop.
class Divide { | |
public static int divide(int dividend, int divisor) throws Exception { | |
int result = 0; | |
int sign = 1; | |
if (divisor == 0) { | |
System.out.println("Divide by 0 error"); | |
throw new Exception("Divide by 0"); | |
} | |
if (divisor < 0 ) { | |
sign *= -1; | |
divisor *= -1; | |
} | |
if (dividend < 0) { | |
sign *= -1; | |
dividend *= -1; | |
} | |
while (dividend > divisor) { | |
dividend -= divisor; | |
result++; | |
} | |
return result * sign; | |
} | |
public static void main(String[] args) { | |
try { | |
int res = Divide.divide(-7,-3); | |
System.out.println(res); | |
} | |
catch(Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
use SoftDeletes;
protected $table = 'cities';
/**
* Use timestamps
*
* @var boolean
*/
public $timestamps = true;
protected $fillable = ['name'];
protected $dates = [];
/**
* districts
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function districts()
{
return $this->hasMany(District::class, 'city_id');
}
public function wards()
{
return $this->hasManyThrough(Ward::class, District::class);
}
$(document).ready(function() {
$(document).on('click', '.delete-city', function(event) {
event.preventDefault();
showConfirm(event.currentTarget);
})
});
function showConfirm(e) {
Swal.fire({
title: 'Are you sure?',
html: "<p>Delete <b>" + $(e).data('name') + "</b></p> <p>You won't be able to revert this!</p>",
icon: 'warning',
showCancelButton: true,
cancelButtonColor: '#3085d6',
confirmButtonColor: '#d33',
confirmButtonText: 'Confirm'
}).then((result) => {
if (result.isConfirmed) {
ajaxDelete(e);
}
});
}
function ajaxDelete(e) {
var url = $(e).prop('href');
var id = $(e).data('id');
$.ajax({
method: "POST",
url: url,
data: {
id: id
}
}).done(function(response) {
let reload_url = $(e).data('return-url');
let target = $('#city-list');
reloadWardList(reload_url, target);
Swal.fire(
'Deleted!',
response.message,
'success'
);
}).fail(function(response) {
Swal.fire(
'Error',
response.responseJSON.message,
'error'
)
});
}
function reloadWardList(url, target) {
$.ajax({
method: 'GET',
url: url
}).done(function(response) {
$(target).html(response.data);
}).fail(function() {
Swal.fire(
'Error',
'Unable to reload the Ward list. Try again.',
'error'
)
});
}
Router::get('/city/add','App\Controllers\CityController@AddForm');
Router::post('/city/add','App\Controllers\CityController@add');
Router::get('/city/list','App\Controllers\CityController@city_list');
Router::post('/city/delete','App\Controllers\CityController@delete');
Router::get('/city/edit/(\d+)','App\Controllers\CityController@showFormedit');
Router::post('/city/edit','App\Controllers\CityController@edit');
<VirtualHost *:80>
DocumentRoot "D:/htdocs/mvc/public/"
ServerName mvc.local
ErrorLog "error.log"
CustomLog "access.log" common
<Directory "D:/htdocs/mvc/public/">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
Allow from all
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?url=$1
<VirtualHost *:80>
DocumentRoot "D:/htdocs/mvc/public/"
ServerName mvc.local
ErrorLog "error.log"
CustomLog "access.log" common
<Directory "D:/htdocs/mvc/public/">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
Allow from all
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?url=$1
helllo moi ng
public function AddForm()
{
return $this->render('address/city-add');
}
public function add()
{
$name = $_POST['name_city'] ?? null;
$fag = 1;