import java.io.*;
public class Main {
public static void main(String args[])
{
BufferedReader brIn = new BufferedReader(new InputStreamReader(System.in));
int pozycja = 0;
String line = " ";
String szukacz = " ";
try
{
{
System.out.println("Wprowadz tekst:");
line = brIn.readLine();
System.out.println("Wprowadzona linia to: " +line);
System.out.println("Czego szukasz");
szukacz = brIn.readLine();
}
}
catch(IOException e)
{
System.out.println("Bład");
}
for (int i = 0; i < line.length(); i++)
{
pozycja = line.indexOf(szukacz);
if (pozycja > 0)
{
System.out.println("Szukana fraza wystepuje na pozycji: ");
System.out.println(+(pozycja+1));
break;
}
else
{
System.out.println("Szukana fraza nie wystepuje");
break;
}
}
}
}
Tutaj będę umieszczał programy mojego autorstwa zrealizowane głównie w języku c++/c.
lecz wbrew temu, co o niej wiemy.
Fox Mulder w serialu „Z archiwum X”
27.11.08
Wyszukiwanie tekstu w wprowadzonym tekście
23.11.08
Losowanie liczb i sortowanie bąbelkowe JAVA
class Main
{
public static void main(String args[])
{
int a;
LosujeSortuje klasa = new LosujeSortuje();
WezLiczbe zaczytaj = new WezLiczbe();
System.out.println("Podaj liczbe elementow tablicy: ");
a = (int)zaczytaj.getDouble("n = ");
klasa.losuje(a);
System.out.println("Elementy tablicy przed posortowaniem:");
klasa.wyswietl(a);
System.out.println("Elementy tablicy po sortowaniu:");
klasa.sortuje(a);
klasa.wyswietl(a);
}
}
Klasa LosujeSortuje:
import java.util.Random;
public class LosujeSortuje {
int t[];
public void losuje(int n)
{
this.t = new int[n];
for (int i = 0; i < n; i++)
{
Random random = new Random();
this.t[i] = random.nextInt();
}
}
public void wyswietl(int n)
{
for (int i = 0; i < n; i++)
{
System.out.println(+this.t[i]);
}
}
public void sortuje(int n)
{
for (int i = n-1; i > 0; i--)
for (int j = 0; j < i; j++)
{
if (this.t[j] > this.t[j + 1])
{
int temp;
temp = this.t[j];
this.t[j] = this.t[j + 1];
this.t[j + 1] = temp;
}
}
}
}
Klasa WezLiczbe
class WezLiczbe {
public double getDouble(String s)
{
char c;
StringBuffer buf = new StringBuffer();
String sx;
double x;
System.out.print(s);
// pobierz x z konsoli jako ciąg znaków
try
{
while ((c = (char) System.in.read() ) != '\n')
buf.append(c);
// przekonwertuj x z typu String na typ double
sx = buf.toString();
x = Double.parseDouble( sx );
} catch (java.io.IOException e) { x = 0; };
buf.setLength(0); // oczyść bufor
return x;
}
}
12.11.08
Równanie kwadratowe zapisane w JAVIE
public class Main {
public static void main (String args[])
{
double a;
double b;
double c;
double x1, x2, delta, pierwiastek;
WezLiczbe zaczytaj = new WezLiczbe();
System.out.println("PIERWIASTKÓW RÓWNANIA KWADRATOWEGO");
System.out.println();
System.out.println("Podaj parametry równania ");
a = (double)zaczytaj.getDouble("a = ");
b = (double)zaczytaj.getDouble("b = ");
c = (double)zaczytaj.getDouble("c = ");
delta = (b*b) - (4*c*a);
pierwiastek = Math.sqrt(delta);
//przypadek równania liniowego
if (a == 0)
{
System.out.println("Równanie liniowe");
System.out.println("y = "+b+"*x+"+c);
System.out.println("x = " +((-c)/b));
}
//przypadek gdy delta mniejsza od zera
if (delta < 0)
{
System.out.println("Brak rozwiązań");
}
if (delta == 0)
{
System.out.println("Jeden pierwiastek x = " +((-b)/(2*a)));
}
if (delta > 0)
{
x1 = (-b + pierwiastek)/(2*a);
x2 = (-b - pierwiastek)/(2*a);
System.out.println("Dwa pierwiastki");
System.out.println(+x1);
System.out.println(+x2);
}
}
}
KLASA WEŹ LICZBĘ (do umieszczenia w odrębnym pliku)
class WezLiczbe {
public double getDouble(String s)
{
char c;
StringBuffer buf = new StringBuffer();
String sx;
double x;
System.out.print(s);
// pobierz x z konsoli jako ciąg znaków
try
{
while ((c = (char) System.in.read() ) != '\n')
buf.append(c);
// przekonwertuj x z typu String na typ double
sx = buf.toString();
x = Double.parseDouble( sx );
} catch (java.io.IOException e) { x = 0; };
buf.setLength(0); // oczyść bufor
return x;
}
}