This repository has been archived by the owner on Jun 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kirsing_3.java
51 lines (50 loc) · 1.77 KB
/
kirsing_3.java
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
42
43
44
45
46
47
48
49
50
51
import java.util.Arrays;
import java.util.Scanner;
public class kirsing_3 {
public static void main(String[] args){
System.out.println("Ülesanne 1: ");
ül1();
System.out.println("Ülesanne 2:");
ül2();
}
public static void ül1(){
Scanner sc=new Scanner(System.in);
System.out.print("Sisesta esimene rida: ");
String es = sc.nextLine();
System.out.print("Sisesta teine rida: ");
String te = sc.nextLine();
if(es.equals(te)) System.out.println("Read on samad");
else System.out.println("Read ei ole samad");
sc.close();
}
public static void ül2(){
Scanner sc=new Scanner(System.in);
int num, sum = 0;
while(true){
System.out.print("Sisesta number (1-5): ");
num = sc.nextInt();
if(num >= 1 && num <= 5){
int[] arr = new int[num];
while(true){
try{
System.out.print("Sisesta massiivi numbrid (tühikuga eraldatud): ");
for(int i=0; i < arr.length; i++){
arr[i] = sc.nextInt();
sum += arr[i];
}
break;
}
catch(Exception e) {
System.err.println("Sisesta ainult täisarve!");
sc.next();
}
}
System.out.println("Sisestatud massiiv on: " + Arrays.toString(arr));
System.out.println("Massiivi liikmete summa on: " + sum);
break;
}
else System.out.println("Vale sisend!");
}
sc.close();
}
}