Level 3
Level 3
System.out.print(a[size--]);
}
System.out.println();
}
static void count(int a[]){
for(int i=0;i<a.length;i++) {
int count=0;
for(int j=i+1;j<a.length;j++) {
if(a[i]==a[j]) {
count++;
}
}
if(count>0) {
System.out.print(a[i]);
}
}
System.out.println();
}
static void evenarray(int a[]) {
for(int i=0;i<a.length;i++) {
System.out.println((i%2==0)?"even="+a[i]+"\n":"odd="+a[i]+"\n");
}
}
static void smallsumlarge(int a[]) {
int small=Integer.MAX_VALUE;
int large=Integer.MAX_VALUE;
int total=0;
for(int c:a) {
if(c<small) {
small=c;
}
if(c>large) {
large=c;
}
total+=c;
}
System.out.println("min:"+small+"\nlarge: "+large+"\ntotal"+total);
}
static void ascending(int a[]) {
for(int i=0;i<a.length;i++) {
for(int j=i+1;j<a.length;j++) {
if(a[i]>a[j]) {
int first=a[i];
int second=a[j];
int third=first;
a[i]=second;
a[j]=third;
}
}
}
System.out.println("ascending order");
for(int c:a) {
System.out.print(c);
}
System.out.println();
for(int i=0;i<a.length;i++) {
for(int j=i+1;j<a.length;j++) {
if(a[i]<a[j]) {
int first=a[i];
int second=a[j];
int third=first;
a[i]=second;
a[j]=third;
}
}
}
System.out.println("descending order");
for(int c:a) {
System.out.print(c);
}
System.out.println();
}
static void pat(int a) {
for(int i=1;i<=a;i++) {
for(int sp=0;sp<a-i;sp++) {
System.out.print(" ");
}
for(int j=0;j<i;j++) {
System.out.print("* ");
}
System.out.println();
}
System.out.println();
System.out.println();
for(int i=a;i>0;i--) {
for(int sp=0;sp<a-i;sp++) {
System.out.print(" ");
}
for(int j=0;j<i;j++) {
System.out.print("* ");
}
System.out.println();
}
}
static void sim_pat(int a) {
for(int i=0;i<a;i++) {
for(int sp=0;sp<=i;sp++) {
System.out.print("* ");
}
System.out.println();
}
System.out.println();
}
//recursion lower triangle
static void rec(int a) {
int l=a;
if(a>0) {
for(int i=0;i<a;i++) {
System.out.print("* ");
}
System.out.println();
rec(a-1);
}
}
//recursion my logic upper triangle
static void rec2(int a) {
int n=0;
inner(n,a);
}
}
//recursion chatgpt
static void star(int n) {
if(n==0) {
return;
}
System.out.print("* ");
star(n-1);
}
static void pattern(int a) {
if(a==0) {
return;
}
pattern(a-1);
star(a);
System.out.println();
}
static void alternative(int a[]) {
for(int i=0;i<a.length/2;i++) {
System.out.print(a[i]+" "+a[(a.length-1)-i]+" ");
}
System.out.println((a.length%2==0)?"":a[(a.length/2)]);
}
static void multiply(int a[][],int b[][]) {
int c[][]=new int[a.length][a[0].length];
for(int i=0;i<a.length;i++) {
for(int j=0;j<a.length;j++) {
for(int w=0;w<a.length;w++) {
c[i][j]+=a[i][w]*b[w][j];
}
}
}
for(int[] h:c) {
for(int k:h) {
System.out.print(k+" ");
}
System.out.println();
}
}
static void add(int a[][],int b[][]) {
int c[][]=new int[a.length][a[0].length];
for(int i=0;i<a.length;i++) {
for(int j=0;j<a.length;j++) {
c[i][j]=a[i][j]+b[i][j];
}
}
for(int[] h:c) {
for(int k:h) {
System.out.print(k+" ");
}
System.out.println();
}
}
static void sub(int a[][],int b[][]) {
int c[][]=new int[a.length][a[0].length];
for(int i=0;i<a.length;i++) {
for(int j=0;j<a.length;j++) {
c[i][j]=a[i][j]-b[i][j];
}
}
for(int[] h:c) {
for(int k:h) {
System.out.print(k+" ");
}
System.out.println();
}
}}
Output:
1234134
4314321
134
even=6
odd=4
even=5
odd=6
even=7
min:4
large: 2147483647
total28
ascending order
45667
descending order
76654
*
**
***
****
*****
*****
****
***
**
*
*
**
***
****
*****
*****
****
***
**
*
*
**
***
****
*****
*
**
***
****
*****
192837465
33
77
23
45
01
23