Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ZADATAK 1
- import java.util.Scanner;
- public class Matrica {
- public static void main(String[] args) {
- Scanner ulaz = new Scanner(System.in);
- int M = 0;
- System.out.println("Unesite dimenziju kvadratne matrice (broj mora biti u intervalu između 2 i 6):");
- do {
- M = ulaz.nextInt();
- } while (M < 3 || M > 5);
- int matrica[][] = new int[M][M];
- System.out.println("Ispunite matricu cijelim brojevima:");
- for(int i = 0; i < M; i++) {
- for(int j = 0; j < M; j++) {
- matrica[i][j] = ulaz.nextInt();
- }
- }
- System.out.println("Brojevi sporedne dijagonale: ");
- for(int i = 0; i < M; i++) {
- for(int j = 0; j < M; j++) {
- if(i + j == M - 1 && matrica[i][j] < matrica[0][0] && matrica[i][j] < matrica[M-1][M-1])
- System.out.println(matrica[i][j]);
- }
- }
- ulaz.close();
- }
- }
- //ZADATAK 2
- import java.util.Scanner;
- public class IspisPrirodnihBrojeva {
- public static void main(String[] args) {
- Scanner ulaz = new Scanner(System.in);
- int N, brojac = 0;
- System.out.println("Unesite prirodni broj N:");
- do {
- N = ulaz.nextInt();
- }while(N < 1);
- System.out.println("Brojevi djeljivi s 5 u unesenom intervalu: ");
- for(int i = 1; i < N; i++) {
- if(i % 5 == 0) {
- if(brojac == 5) return;
- System.out.println(i);
- brojac++;
- }
- }
- ulaz.close();
- }
- }
- //ZADATAK 3
- import java.io.BufferedWriter;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.Scanner;
- public class ProvjeraRecenice {
- public static void main(String[] args) {
- Scanner ulaz = new Scanner(System.in);
- String recenica = null;
- int zadnjiIndeks = 0;
- while(true) {
- recenica = ulaz.nextLine();
- if(recenica.equals("STOP"))
- break;
- zadnjiIndeks = recenica.length() - 1;
- if(Character.isLowerCase(recenica.charAt(0))) {
- recenica = recenica.substring(0, 1).toUpperCase() + recenica.substring(1);
- }
- if(recenica.charAt(zadnjiIndeks) != '.') {
- recenica += '.';
- }
- spremiUDatoteku(recenica);
- }
- ulaz.close();
- }
- public static void spremiUDatoteku(String rec) {
- BufferedWriter bw = null;
- FileWriter fw = null;
- try {
- fw = new FileWriter("recenice.txt", true);
- bw = new BufferedWriter(fw);
- bw.write(rec);
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- try {
- if (bw != null)
- bw.close();
- if (fw != null)
- fw.close();
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
- }
- }
- //ZADATAK 4
- public class Automobil {
- private int spremnik;
- private double potrosnja;
- private String vrstaGoriva, tip, marka;
- Automobil() {
- spremnik = 0;
- potrosnja = 0.0;
- vrstaGoriva = null;
- tip = null;
- marka = null;
- }
- Automobil(int spremnik, double potrosnja, String vrstaGoriva, String tip, String marka) {
- this.spremnik = spremnik;
- this.potrosnja = potrosnja;
- this.vrstaGoriva = vrstaGoriva;
- this.tip = tip;
- this.marka = marka;
- }
- public int getSpremnik() {
- return spremnik;
- }
- public void setSpremnik(int spremnik) {
- this.spremnik = spremnik;
- }
- public double getPotrosnja() {
- return potrosnja;
- }
- public void setPotrosnja(double potrosnja) {
- this.potrosnja = potrosnja;
- }
- public String getVrstaGoriva() {
- return vrstaGoriva;
- }
- public void setVrstaGoriva(String vrstaGoriva) {
- this.vrstaGoriva = vrstaGoriva;
- }
- public String getTip() {
- return tip;
- }
- public void setTip(String tip) {
- this.tip = tip;
- }
- public String getMarka() {
- return marka;
- }
- public void setMarka(String marka) {
- this.marka = marka;
- }
- }
- public class Test extends Automobil {
- private double potrosio_goriva, prijeden_put;
- public double getPotrosio_goriva() {
- return potrosio_goriva;
- }
- public void setPotrosio_goriva(double potrosio_goriva) {
- this.potrosio_goriva = potrosio_goriva;
- }
- public double getPrijeden_put() {
- return prijeden_put;
- }
- public void setPrijeden_put(double prijeden_put) {
- this.prijeden_put = prijeden_put;
- }
- }
- public class Izracun {
- public static void usporedi(Test t1, Test t2) {
- if((t1.getSpremnik()-t1.getPotrosio_goriva()) / (t1.getPrijeden_put() / 100) < (t2.getSpremnik()-t2.getPotrosio_goriva()) / (t2.getPrijeden_put() / 100)) {
- System.out.println("Prvi automobil je stedljiviji.");
- }
- System.out.println("Drugi automobil je stedljiviji.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement