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

Public Static Int Isincreasingsequence: in Out

The document contains code for two Java programs. The first program takes an array of integers as input and checks if it is an increasing sequence by iterating through the array and comparing each element to its index value. It returns 1 if it is an increasing sequence or 0 if it is not. The second program takes a single integer as input, calculates the cube of each digit and sums them, and checks if the sum equals the original number. It returns 1 if they are equal or 0 if they are not. Both programs take user input, call the checking methods, and print the return value.

Uploaded by

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

Public Static Int Isincreasingsequence: in Out

The document contains code for two Java programs. The first program takes an array of integers as input and checks if it is an increasing sequence by iterating through the array and comparing each element to its index value. It returns 1 if it is an increasing sequence or 0 if it is not. The second program takes a single integer as input, calculates the cube of each digit and sums them, and checks if the sum equals the original number. It returns 1 if they are equal or 0 if they are not. Both programs take user input, call the checking methods, and print the return value.

Uploaded by

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

Q1.

import java.util.Scanner;

public class Question {


public static int isIncreasingSequence( int[ ] a ){
int end = 1;// end of the current sequence
int index = 0; // index of the array

while( index < a.length ){


//Iterate through a larger and larger subsequence
for(int i = 1; i <= end ; i++){
if( a[index] != i) return 0;

index++;
if(index == a.length) break;
}
end++;
}
return 1;
}

public static void main(String [] a){


Scanner input = new Scanner(System.in);

System.out.print("How many number do you want to enter: ");


int num = input.nextInt();
int Arr[] = new int[num];

System.out.println("Enter the " + num + " " + "numbers now: ");


for(int i = 0; i < Arr.length; i++){
Arr[i] = input.nextInt();
}

int result = isIncreasingSequence(Arr);


System.out.println(result);

}
}
Q2.

import java.util.Scanner;

public class Quesiton2 {

public static int isCubePowerfull(int num){


int originalNum, digit , cubeSum = 0;
originalNum = num;

while(num != 0){
digit = num % 10;
cubeSum = cubeSum + (digit * digit * digit);
num = num / 10;
}
if(cubeSum == originalNum){
return 1;
}
return 0;
}

public static void main(String [] a){


int originalNum , digit , cubesum = 0, num;
System.out.print("Enter a number: ");
Scanner input = new Scanner(System.in);

int number = input.nextInt();


int result = isCubePowerfull(number);
System.out.println(result);
}
}

You might also like