0% found this document useful (0 votes)
4 views8 pages

Lab Java 1

Uploaded by

emanuela demko
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views8 pages

Lab Java 1

Uploaded by

emanuela demko
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

UNIVERSITETI POLITEKNIK I TIRANES

FAKULTETI I TEKNOLOGJISE SE INFORMACIONIT


DEPARTAMENTI I INXHINIERISE INFORMATIKE

PUNE LABORATORI NR.1

Dega: Inxhinieri Informatike

Lënda:Programim i Orientuar nga Objekti

Grupi:ll-A
Ushtrimi1
Ndertoni nje program ne Java mini-calculator, i cili pyet perdoruesin te
zgjedhe nje operator midis +, -, x, / dhe te jape 2 numra nga 1 deri ne
99.Kalkulatori implementon algoritmin e veprimeve aritmetike, llogarit
rezultatin final dhe e shfaq ate ne ekran.Programi duhet te kontrolloje
nese operatoret dhe numrat e dhene nga perdoruesi jane korrekt.Nese
inputi nuk eshte korrekt, programi duhet ta pyese perdoruesin qe te jape
serish te dhenat pa e perfunduar programin.Del nga programiduke
shtypur q.
Zgjidhje:
import java.util.*;

public class Ushtrimi1 {

public static void main(String[] args) {

Scanner in= new Scanner(System.in);

char A;

int B,C,D;

System.out.println("*****************************************************
*****");
System.out.println("\t\t **Kalkulator**");

System.out.println("*****************************************************
*****");
boolean f=true;

while(f==true) {
System.out.println("Zgjidhni operatorin qe doni te perdorni(’+’, ’-’,
’x’, ’/’) ose shtypni ‘q’ per te dale : ");
A=in.next().charAt(0);

if(A=='q') {

System.out.println("Mirupafshim");

break;
}
System.out.println("Shtypni vleren e pare: ");
B=in.nextInt();

System.out.println("Shtypni vleren e dyte: ");


C=in.nextInt();

if( ((A=='+') ||(A=='-') ||(A=='x')||(A=='/') ||(A=='q')) && ((B>=1) &&


(B<=99)) && ((C>=1) && (C<=99)) )
f=true;

else {
System.out.println("Te dhenat jane dhene gabim.Provoni perseri!\n");
continue;
}
if(A=='+') {
D=B+C;
System.out.println("Shuma: " + D);
}

else if(A=='-') {
D=B-C;
System.out.println("Diferenca: " + D);
}

else if(A=='x') {
D=B*C;
System.out.println("Prodhimi eshte: " + D);
}

else {
D=B/C;
System.out.println("Pjestimi eshte: " + D);
}

}
Ushtrimi 2

Gjeneroni daljen si ne figure


Zgjidhje:
import java.util.*;

public class Ushtrimi2 {

public static void main(String[] args) {


// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);

int i,j,k;

int tedhenat;

System.out.println("Jepni te dhenat e figures: ");


tedhenat= in.nextInt();
System.out.printf("\n");

//pjesa lart
int a, b;

int l=(tedhenat*2)+4;

a=(l-1)/2;
b=l/2;

for(i=0; i<tedhenat; i++) {

for(j=0; j<l; j++) {

if(j<a-1-i || j>b+i+1)

System.out.printf(" ");

else if( ((j>=a-1-i || j<=b+i+1)) && ((j!=a) && (j!=b)) )

System.out.printf("/");

else System.out.printf("*");
}
System.out.printf("\n");
}

System.out.printf("+");

for(i=0;i<l/2-1;i++) System.out.printf("=*");

System.out.printf("+\n");
//figura 1

for(i=0;i<(tedhenat+1)/2;i++) {

System.out.printf("|");

for(j=2;j<l;j++) {

if ( !(j<(tedhenat/2)-i+2 || (j>(tedhenat/2)+i+2 && j<(3*tedhenat/2)-i+3)


||

j>(3*tedhenat/2)+i+3) ) {

System.out.printf("/\\");
j+=1;
else
System.out.printf(".");
}
System.out.printf("|\n");
}

for(i=tedhenat/2;i>=0;i--){
System.out.printf("|");

for(j=2;j<l;j++){
if( !(j<(tedhenat/2)-i+2 || (j>(tedhenat/2)+i+2 && j<(3*tedhenat/2)-i+3)
|| j>(3*tedhenat/2)+i+3) ) {

System.out.printf("\\/");
j+=1;
}

else
System.out.printf(".");
}
System.out.printf("|\n");
}

System.out.printf("+");

for(i=0;i<l/2-1;i++)

System.out.printf("=*");

System.out.printf("+\n");
//figura 2

for(i=tedhenat/2;i>=0;i--){

System.out.printf("|");

for(j=2;j<l;j++){

if( !(j<(tedhenat/2)-i+2 || (j>(tedhenat/2)+i+2 && j<(3*tedhenat/2)-i+3)


||

j>(3*tedhenat/2)+i+3) ) {

System.out.printf("\\/");

j+=1;
}
else

System.out.printf(".");
}
System.out.printf("|\n");
}
for(i=0;i<(tedhenat+1)/2;i++) {

System.out.printf("|");

for(j=2;j<l;j++) {

if ( !(j<(tedhenat/2)-i+2 || (j>(tedhenat/2)+i+2 && j<(3*tedhenat/2)-i+3)


||

j>(3*tedhenat/2)+i+3) ) {

System.out.printf("/\\");

j+=1;
}
else

System.out.printf(".");
}
System.out.printf("|\n");
}
System.out.printf("+");

for(i=0;i<l/2-1;i++) System.out.printf("=*");

System.out.printf("+\n");
//figura fundit
a=(l-1)/2;
b=l/2;

for(i=0; i<tedhenat; i++) {

for(j=0; j<(tedhenat*2)+4; j++) {

if(j<a-1-i || j>b+i+1)

System.out.printf(" ");

else if( ((j>=a-1-i || j<=b+i+1)) && ((j!=a) && (j!=b)) )

System.out.printf("/");

else System.out.printf("*");
}
System.out.printf("\n");

You might also like