-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patharray_o1-2.java
More file actions
42 lines (35 loc) · 1.43 KB
/
array_o1-2.java
File metadata and controls
42 lines (35 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package test;
import java.util.Scanner;
public class Test{
public static void main(String args[]){
Scanner input = new Scanner(System.in);
int [] result = new int[4]; // how many ing we can add
int [] arr = new int[100]; //max number for input
int counter = 0, count = 0;
Boolean error = false;
int i,temp = 0;
System.out.println("Enter the integers between 1 and 100: ");
String tmp = input.nextLine();
tmp = tmp.trim();//take away leading or after space
for ( i=0; i<tmp.length(); i++){
if(Character.isDigit(tmp.charAt(i))==false) error=true;
else arr[i] = (int)tmp.charAt(i)-48; //(numerisca syffror) something about programmingtrick to find out if this is the umber
}
//Initialize num[] array with user input
for(i=0; i < result.length; i++){
result[i] = input.nextInt();
//expected input will end when user enters zero
if(result[i] == 0){
break;
}
}//end of for loop
for (i =0 ; i < result.length; i++){
if(result[i] > 10 || result[i] == 10 ){
count++;
}
}
if(!error)
System.out.println("Number of the elements more or equal 10 is: "+count + " Number of the elements less than 10 is: "+(4-count));
else System.out.println("wrong data input");
}//end of main
}//end of CountOccurrenceOfNumbers