<fragment
android:id="@+id/fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
fab:defaultNavHost="false"
fab:navGraph="@navigation/nav_graph" />
open class MainActivity : AppCompatActivity() {
private lateinit var navController:NavController
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//creating backArrow
navController=Navigation.findNavController(this,R.id.fragment)
NavigationUI.setupActionBarWithNavController(this,navController)
}
override fun onSupportNavigateUp(): Boolean {
return navController.navigateUp()
}
//https://chetangupta.net/viewbinding/
abstract class ViewBindingFragment<VB : ViewBinding> : Fragment() {
private var _binding: ViewBinding? = null
abstract val bindingInflater: (LayoutInflater, ViewGroup?, Boolean) -> VB
@Suppress("UNCHECKED_CAST")
protected val binding: VB
get() = _binding as VB
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
_binding = bindingInflater.invoke(inflater, container, false)
return requireNotNull(_binding).root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setup()
}
abstract fun setup()
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}
class ProfileFragment :ViewBindingFragment<ProfileLayoutBinding>() {
override val bindingInflater: (LayoutInflater) -> ViewBinding
= ProfileLayoutBinding::inflate
override fun setup(){
//.. do stuff with binding variable
}
}
val fr = FileReader("f.txt")
val array=fr.readText()
.substringAfter(':')
.substringBefore('К')
.split(' ')
.toList()
.filter { !it.contains('0') && !it.contains('-') }
println(array)
fr.close()
val newFw = FileWriter("g4.txt")
var numbers = ""
numbers = array.toString()
.substringAfter('[')
.substringBefore("]")
.filter { !it.isWhitespace() && !it.equals(',') }
newFw.append(numbers)
newFw.close()
fun main() {
val fileName = "f18.txt"
val file = File(fileName)
val fw =FileWriter(file,true)
println("Введите диапазон A: ")
val a = readLine()!!.toInt()
println("Введите диапазон B: ")
val b = readLine()!!.toInt()
if ( a < b )
{
var positive = 0
var negative = 0
println("Введите количество чисел: ")
val count = readLine()!!.toInt()
val massive = IntArray(count)
fw.appendln("Исходный массив:")
fw.flush()
for ( i in 0 until count )
{
massive[i] = (a..b).random()
fw.appendln("${massive[i]} ")
when
{
massive[i] > 0 -> positive++
massive[i] < 0 -> negative++
}
}
fw.appendln("Количество положительных: $positive")
fw.flush()
fw.appendln("Количество отрицательных: $negative")
fw.flush()
when
{
positive > negative -> fw.appendln("В массиве положительных чисел больше отрицательных")
positive < negative -> fw.appendln("В массиве отрицательных чисел больше положительных")
positive == negative -> fw.appendln("В массиве одинаковое количество положительных и отрицательных чисел")
}
fw.flush()
}
else println("Введен не правильный диапазон.")
fw.close()
}
val scope1 = CoroutineScope(CoroutineName("MyCoroutine")+Dispatchers.IO)