public class Micks {
public static void main(String[] args) {
String petReaction;
Pet myPet = new Pet();
myPet.eat();
petReaction = myPet.say(" ==>>");
System.out.println(petReaction);
myPet.sleep();
Fish myFish = new Fish();
myFish.dive(0);
myFish.dive(1);
myFish.dive(2);
myFish.dive(3);
myFish.dive(4);
myFish.dive(5);
myFish.dive(6);
myFish.dive(7);
myFish.dive(8);
myFish.dive(9);
myFish.sleep();
String fishReaction = myFish.say(" \u00bb ");
System.out.println(fishReaction);
}
}
class Pet {
int age;
float weight;
float height;
String color;
public void sleep(){
System.out.println(" ");
}
public void eat(){
System.out.println("newDeep [ ] + currentSUMM [ ] "+"\n");
}
public String say(String aWord){
String petResponse = " = currentSUMM [ ]"+"\n"+aWord;
return petResponse;
}
}
class Fish extends Pet {
int currentSUMM=0;
public int dive(int newDeep){
currentSUMM += newDeep;
System.out.println(" newDeep = [" + newDeep + "]");
System.out.println(" currentSUMM = [" + currentSUMM + "]");
return currentSUMM;
}
@Override
public String say(String something){
return "\n"+"currentSUMM = "+currentSUMM;
}
}
run :=================================
newDeep [ ] + currentSUMM [ ]
= currentSUMM [ ]
==>>
newDeep = [0]
currentSUMM = [0]
newDeep = [1]
currentSUMM = [1]
newDeep = [2]
currentSUMM = [3]
newDeep = [3]
currentSUMM = [6]
newDeep = [4]
currentSUMM = [10]
newDeep = [5]
currentSUMM = [15]
newDeep = [6]
currentSUMM = [21]
newDeep = [7]
currentSUMM = [28]
newDeep = [8]
currentSUMM = [36]
newDeep = [9]
currentSUMM = [45]
currentSUMM = 45
Exit

import java.io.*;
public class Exit {
public static void outFile(String str) {
String fileName="C:/Users/admin/Documents/sim_En.txt";
boolean isAppend=false;
try (FileWriter writer=new FileWriter(fileName , isAppend)) {
writer.write(str);
}catch(IOException ex){
System.out.println(ex.getMessage());
}
}
public static void main(String[] args) {
String fileName = "C:/Users/admin/Documents/s.txt";
FileInputStream inputStream = null;
try {
byte[] buffer = new byte[95];
String str="";
inputStream = new FileInputStream(fileName);
int total = 0;
int nRead = 0;
while ((nRead = inputStream.read(buffer)) != -1) {
System.out.println(new String(buffer));
total += nRead;
}
System.out.println("Read " + total + " bytes");
str=new String(buffer,"UTF-8");
outFile(str);
} catch (FileNotFoundException ex) {
System.out.println("Unable to open file '" + fileName + "'");
} catch (IOException ex) {
System.out.println("Error reading file '" + fileName + "'");
} finally {
try {
if (inputStream != null) {
inputStream.close();
}
} catch (IOException e) {
}
}
}
}
Lab_file
![]()
import java.io.*;
public class Lab_file {
public static void outFile(String str) {
String fileName="C:/Users/rodomod/Documents/F.txt";
boolean isAppend=false;
try (FileWriter writer=new FileWriter(fileName , isAppend)) {
writer.write(str);
}catch(IOException ex){
System.out.println(ex.getMessage());
}
}
public static void main(String[]args) throws IOException {
RandomAccessFile file=new RandomAccessFile("C:/Users/rodomod/Documents/d.txt","r");
byte[]bytes=new byte[95];
file.read(bytes);
String str="";
str=new String(bytes,"UTF-8");
System.out.print(str);
outFile(str);
}
}
petMaster
![]()
public class PetMaster {
public static void main(String[] args) {
String petReaction;
Pet myPet = new Pet();
myPet.eat();
petReaction = myPet.say("Обойдусь!");
System.out.println(petReaction);
myPet.sleep();
Fish myFish = new Fish();
myFish.dive(2);
myFish.dive(3);
myFish.sleep();
String fishReaction = myFish.say(" \u00bb ");
System.out.println(fishReaction);
}
}
class Pet {
int age;
float weight;
float height;
String color;
public void sleep(){
System.out.println("Спокойной ночи! До завтра");
}
public void eat(){
System.out.println("Я очень голоден, давайте перекусим чипсами!"+"\u0420\u045b\u0421\u201a\u0420\u0457\u0421\u0402\u0420\u00b0\u0420\u0406\u0420\u00bb\u0421\u040f\u0420\u00b5\u0420\u0458\u005f\u0420\u00b7\u0420\u00b0\u0420\u0456\u0420\u0455\u0420\u00bb\u0420\u0455\u0420\u0406\u0420\u0454\u0420\u0451\u005f\u0420\u0457\u0420\u0455\u005f\u0421\u0403\u0420\u0455\u0420\u0454\u0420\u00b5\u0421\u201a\u0421\u0453");
}
public String say(String aWord){
String petResponse = "Ну ладно!! " +aWord;
return petResponse;
}
}
class Fish extends Pet {
int currentDepth=0;
public int dive(int howDeep){
currentDepth=currentDepth + howDeep;
System.out.println("Ныряю на глубину " + howDeep + " футов");
System.out.println("я на глубине " + currentDepth + " футов ниже уровн¤ моря");
return currentDepth;
}
@Override
public String say(String something){
return " “ Ты чё не знаешь, что рыбы не разговаривают ?_? “ \u00bb ";
}
}
perebor

import java.io.*;
class Perebor {
public static void outFile(String str) {
String fileName = "outFile.txt"; // файл куда будем записывать
boolean isAppend = false; // можно ли дабавлять в файл?
try (FileWriter writer = new FileWriter(fileName, isAppend)){
// запись всей строки
writer.write(str);
// запись по символам
//writer.append('\n');
//writer.append('E');
} catch (IOException ex) {
System.out.println(ex.getMessage());
}
}
public static void main(String[] args) throws java.lang.Exception
{
// your code goes here
char abc[] = new char[] {'!','"','#','$','%','&','(',')','*','+',',','-','.','/','0','1','2','3','4','5','6','7','8','9',':',';','<','=','>','?','@','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','[',']','_','`','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','{','|','}',' ','~','^'}; // множество допустимых символов без : (',\)
int size = 2; //кол-во элементов
String outString = ""; //сюда мы будем сохранять то что запишем в конце работы программы
int arr[] = new int[size]; //массив для хранения текущего варианта множества
outer:
while (true) { //вечный цикл
//вывод варианта множества на экран
for (int ndx : arr) {
System.out.print(abc[ndx]);
outString += abc[ndx];
}
System.out.println();
outString +='\n';
int i = size - 1; //ставим курсов в самую правую ячейку
while (arr[i] == abc.length - 1) { //движемся влево, если ячейка переполнена
arr[i] = 0; //записываем в ячейку 0, т.к. идет перенос разряда
i--; //сдвиг влево
//если перенос влево невозможен, значит перебор закончен
if (i < 0) break outer;
}
arr[i]++; //увеличиваем значение ячейки на единицу
}
outFile(outString);
}
}
Ideone

import java.io.*;
class Ideone {
public static void outFile(String str) {
String fileName = "outFile.txt"; // файл куда будем записывать
boolean isAppend = false; // можно ли дабавлять в файл?
try (FileWriter writer = new FileWriter(fileName, isAppend)){
// запись всей строки
writer.write(str);
// запись по символам
//writer.append('\n');
//writer.append('E');
} catch (IOException ex) {
System.out.println(ex.getMessage());
}
}
public static void main(String[] args) throws java.lang.Exception
{
// your code goes here
char abc[] = new char[]{'0','1','2','3','4','5','6','7','8','9'}; //множество допустимых символов
int size = 4; //кол-во элементов
String outString = ""; //сюда мы будем сохранять то что запишем в конце работы программы
int arr[] = new int[size]; //массив для хранения текущего варианта множества
outer:
while (true) { //вечный цикл
//вывод варианта множества на экран
for (int ndx : arr) {
System.out.print(abc[ndx]);
outString += abc[ndx];
}
System.out.println();
outString +='\n';
int i = size - 1; //ставим курсов в самую правую ячейку
while (arr[i] == abc.length - 1) { //движемся влево, если ячейка переполнена
arr[i] = 0; //записываем в ячейку 0, т.к. идет перенос разряда
i--; //сдвиг влево
//если перенос влево невозможен, значит перебор закончен
if (i < 0) break outer;
}
arr[i]++; //увеличиваем значение ячейки на единицу
}
outFile(outString);
}
}