Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

1.

package array;
import java.util.Scanner;//Name Amanuel Bazezew Id 1200876
public class Array{
public static int isSystematicalyIncreasing(int[] array) {
int end = 1; // Track the end of the current sequence
int index = 0; // Track the index of the array
while (index < array.length) {
// Iterate through a larger and larger subsequence
for (int i = 1; i <= end; i++) {
if (array[index] != i) return 0;
index++;
if (index == array.length) break;
}
end++;
}
return 1;
}
public static void main(String args[]){
int n;
Scanner sc=new Scanner(System.in);
System.out.print("Enter array size: ");
n=sc.nextInt(); //reading the number of elements from the that we want to enter
int[] numberSequence = new int[n];
System.out.println("Enter the elements of the array: ");
for(int i=0; i<n; i++)
{
numberSequence[i]=sc.nextInt(); //reading array elements from the user
}
System.out.println("Array elements are: ");
for (int i=0; i<n; i++)
{
System.out.print(numberSequence[i]+" ");
}
System.out.println(" \n..........................................");
System.out.println("output= "+isSystematicalyIncreasing(numberSequence));
System.out.println();//for readability
System.out.println();
System.out.println();
}
}

2. package newpackage;
import java.util.Scanner;

public class cube power {


public static void main(String []args){

int num=0;
String f="0";
String s="1";
int i;
Scanner n1 = new Scanner (System.in);
System.out.println("Enter number: ");
int n=n1.nextInt();
int c=n;

while (n>0){
i=n%10;
n=n/10;
num += i*i*i;
}
if (num == c){
System.out.println("OUTPUT "+s);
}
else{
System.out.println("OUTPUT "+f);
}
}
}

You might also like