Question:-
Jose gets n numbers in an array. Write a Java program to take the single digit odd numbers in the array and make a number by combining those odd numbers alone.Example: If the array is {2,7,14,24,41,3} the output should be a single number 73, if not found print “Single digit odd number is not found in the array”.If the array size is zero or lesser then display the message as “Invalid array size”
Sample Input 1:
Enter the size of an array:
4
Enter the array elements:
45
3
56
7
Sample Output 1:
37
Sample Input 2:
Enter the size of an array:
0
Sample Output 2:
Invalid array size
Code:-
Main.java
import java.util.Scanner; public class Main { public static void main (String[] args) { Scanner sc=new Scanner(System.in); System.out.println("Enter the size of an array:"); int n=sc.nextInt(); if(n>0) { int arr[]=new int[n]; System.out.println("Enter the array elements:"); for(int i=0;i<n;i++) { arr[i]=sc.nextInt(); } String output=""; for(int j=0;j<n;j++) { if(arr[j]>=0&&arr[j]<10) { if(arr[j]%2!=0) { output=output.concat(String.valueOf(arr[j])); } } } if(output.equals("")) System.out.println("Single digit odd number is not found in the array"); else System.out.println(output); } else { System.out.println("Invalid array size"); } } }
Recommended:-
- Array square
- Generate number using odd digits
- Alternate Number Difference
- Next Greatest number
- Mark Comparison
- Print the characters in descending order
- Vowels in a fishBowl
- Least offer
- Ascending and descending order
- Mail Domain
- Count repeating words
- Sentence – Convert to upper and lower
- Count consecutive repeating characters
- Zig zag Array
- Pass and Fail Count
- Search a Course
- Average and Grade Calculation
- String – Find and replace the character (first occurrence)
- Sort the first and second half of an array
- Retail Shop
- Palindrome
- Numerology
- InitCap
- Array Compatiblilty
- Sum of the maximum and the minimum element
- String Concatenation
- Find Average Age
- Login