-
Notifications
You must be signed in to change notification settings - Fork 0
/
question_practice_of_basic_java.java
141 lines (123 loc) · 3.74 KB
/
question_practice_of_basic_java.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import java.util.Scanner;
import java.util.*;
public class question_practice_of_basic_java {
public static void main(String[] args) {
}
public static void question1(){
System.out.println("Question 1");
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int sum = a + b + c;
int avg = sum/3;
System.out.println(avg);
}
public static void question2() {
System.out.println("Question 2");
Scanner sc = new Scanner(System.in);
System.out.println("enter a number");
int n = sc.nextInt();
int sum = 0;
for(int i = 0; i <=n; i++){
if (i%2 != 0) {
sum = sum + i;
}
}
System.out.println(sum);
}
public static int question3() {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int greater;
if (a > b) {
System.out.println("a is greater");
System.out.println(a);
greater = a;
}else{
System.out.println(" b is greater ");
System.out.println(b);
greater = b;
}
return greater;
}
public static double question4() {
Scanner sc = new Scanner(System.in);
float radius = sc.nextFloat();
double circumference = 2 * 3.14 * radius;
System.out.println("radius of circle is " + circumference);
return circumference;
}
public static String question5() {
Scanner sc = new Scanner(System.in);
int age = sc.nextInt();
if (age>18) {
return "eligible to vote";
}else{
return "ineligible";
}
}
public static void question6() {
int i = 0;
do{
System.out.println("this is an infinite loop using do while loop");
}while(i == 0);
}
public static void question7() {
System.out.println("Enter number of numbers you want to enter");
Scanner sc = new Scanner(System.in);
int numberOfNumbers = sc.nextInt();
int positiveCount = 0;
int negativeCount = 0;
int zeroCount = 0;
for (int i = 0; i < numberOfNumbers; i++){
int enteredNumber = sc.nextInt();
if (enteredNumber == 0) {
zeroCount = zeroCount + 1;
}else if (enteredNumber > 0 ){
positiveCount = positiveCount + 1;
}else{
negativeCount = negativeCount + 1;
}
}
System.out.println("positives" + positiveCount);
System.out.println("negatives" + negativeCount);
System.out.println("zeroes" + zeroCount);
}
public static void question8() {
Scanner sc = new Scanner(System.in);
double x = sc.nextInt();
double n = sc.nextInt();
double ans = Math.pow(x, n);
System.out.println(ans);
}
public static void question9() {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y = sc.nextInt();
int min = Math.min(x, y);
int hcf = 1;
for(int i = 1; i <= min; i++){
if (x%i == 0 & y%i ==0) {
hcf = i;
}
}
System.out.println("HCF" + hcf);
}
public static void question10(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a = 0;
int b = 1;
int c = 0;
System.out.println(a);
System.out.println(b);
for (int i = 0; i < n - 2; i++) {
c = a + b;
System.out.println(c);
a = b;
b = c;
}
}
}