0% found this document useful (0 votes)
26 views2 pages

Java Assignment

The document contains code for two Java programs. The first program defines a method to check if an integer array is systematically increasing. It iterates through the array, comparing each element to its index, and returns 1 if increasing or 0 if not. The main method takes user input to populate an array and calls the isSystematicallyIncreasing method, printing the output. The second program takes user input for a number, calculates its cube root, and checks if it equals the original number, printing 1 if so or 0 if not.

Uploaded by

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

Java Assignment

The document contains code for two Java programs. The first program defines a method to check if an integer array is systematically increasing. It iterates through the array, comparing each element to its index, and returns 1 if increasing or 0 if not. The main method takes user input to populate an array and calls the isSystematicallyIncreasing method, printing the output. The second program takes user input for a number, calculates its cube root, and checks if it equals the original number, printing 1 if so or 0 if not.

Uploaded by

Amanuel Baze
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 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