-
Notifications
You must be signed in to change notification settings - Fork 0
/
jun15-datatypes_userInput.txt
416 lines (329 loc) · 11 KB
/
jun15-datatypes_userInput.txt
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
//STATIC:
public class jun_15 {
public static void main(String[] args){
//67
int a= 67;
System.out.println(a);
--------------------------------------------------------------------
//2.35
float b= 2.35f;
System.out.println(b);
--------------------------------------------------------------------
//w
char c= 'w';
System.out.println(c);
--------------------------------------------------------------------
/*12342
4.56
f
-32
4.5*/
int d1= 12342;
float d2= 4.56f;
char d3= 'f';
int d4= -32;
float d5= 4.5f;
System.out.println(d1);
System.out.println(d2);
System.out.println(d3);
System.out.println(d4);
System.out.println(d5);
--------------------------------------------------------------------
//34+78
int e1= 34;
int e2= 78;
int e= e1+e2;
System.out.println(e);
--------------------------------------------------------------------
//23-6
int f1= 23;
int f2= 6;
int f= f1-f2;
System.out.println(f);
--------------------------------------------------------------------
//45*2
int g1= 45;
int g2= 2;
int g= g1*g2;
System.out.println(g);
--------------------------------------------------------------------
//56/2
int h1= 56;
int h2= 2;
int h= h1/h2;
System.out.println(h);
--------------------------------------------------------------------
//45+78+23+12
int i1=45, i2=78, i3=23, i4=12;
int i= i1+i2+i3+i4;
System.out.println(i);
--------------------------------------------------------------------
//56*34+12/2-13
int j1=56, j2=34, j3=12, j4=2, j5=13;
int j= j1 * j2 + j3 / j4 - j5;
System.out.println(j);
--------------------------------------------------------------------
//1.2*6.7-4.5/2
float k1= 1.2f, k2= 6.7f, k3= 4.5f;
int k4= 2;
float k= k1 * k2 - k3 / k4;
System.out.println(k);
--------------------------------------------------------------------
//1.6*(12-2)/2+7.8-1.5
float l1= 1.6f, l4= 7.8f, l5= 1.5f;
int l2= 12, l3= 2;
float l= l1 * (l2-l3)/l3 + l4 -l5;;
System.out.println(l);
--------------------------------------------------------------------
//4.5*1.2-(82/2)-5.6 +1.234
float m1= 4.5f, m2= 1.2f, m5= 5.6f, m6= 1.234f;
int m3= 82, m4= 2;
float m= m1 * m2 - (m3/m4)- m5 + m6;
System.out.println(m);
--------------------------------------------------------------------
//8*1+(4-2)/1+6
int n1=8, n2=1, n3=4, n4=2, n5=6;
int n= n1 * n2 + (n3-n4)/ n2 + n5;
System.out.println(n);
--------------------------------------------------------------------
//3.4+1.2*(3.7-1.2)/2+6.8
float o1=3.4f, o2=1.2f, o3=3.7f, o5= 6.8f;
int o4=2;
float o= o1 + o2 * (o3-o2)/ o4 + o5;
System.out.println(o);
--------------------------------------------------------------------
//8.9*1.67-(6.21-5.6)+7.8-34 +157
float p1=8.9f, p2= 1.67f, p3=6.21f, p4=5.6f, p5=7.8f;
int p6=34, p7=157;
float p= p1 * p2 - (p3-p4)+ p5 -p6 +p7;
System.out.println(p);
--------------------------------------------------------------------
//Swap numbers (without third variable)
int num1=10;
int num2=20;
System.out.println("real num1: " + num1);
System.out.println("real num2: " + num2);
num1= num1 + num2;
num2= num1 - num2;
num1= num1 - num2;
System.out.println("swapped num1: " + num1);
System.out.println("swapped num2: " + num2);
--------------------------------------------------------------------
//Swap numbers (using third variable)
int no1=6;
int no2=12;
System.out.println("real no1: " + no1);
System.out.println("real no2: " + no2);
int no3=no1;
no1 = no2;
no2= no3;
System.out.println("swapped no1: " + no1);
System.out.println("swapped no2: " + no2);
}
}
--------------------------------------------------------------------
--------------------------------------------------------------------
USER INPUT:
import java.util.Scanner;
public class jun_15userInput {
public static void main(String[] args){
//User Input of all primitive datatypes
Scanner sc= new Scanner(System.in);
byte by;
System.out.print("Enter a byte integer: ");
by= sc.nextByte();
System.out.println(by);
short sh;
System.out.print("Enter a short integer: ");
sh= sc.nextShort();
System.out.println(sh);
int in;
System.out.print("Enter an integer: ");
in= sc.nextInt();
System.out.println(in);
long lo;
System.out.println("Enter a long integer: ");
lo= sc.nextLong();
System.out.println(lo);
float fl;
System.out.print("Enter a float number: ");
fl= sc.nextFloat();
System.out.println(fl);
double db;
System.out.print("Enter a double float number: ");
db= sc.nextDouble();
System.out.println(db);
char ch;
System.out.print("Enter a character: ");
ch= sc.next().charAt(0);
System.out.println(ch);
String str;
System.out.print("Enter a word/words: ");
str= sc.nextLine();
System.out.println(str);
--------------------------------------------------------------------
//67
int a;
System.out.print("Enter a number: ");
a= sc.nextInt();
System.out.println(a);
--------------------------------------------------------------------
//2.35
float b;
System.out.print("Enter a decimal number: ");
b= sc.nextFloat();
System.out.println(b);
--------------------------------------------------------------------
//w
char c;
System.out.print("Enter a character: ");
c= sc.next().charAt(0);
System.out.println(c);
--------------------------------------------------------------------
/*12342
4.56
f
-32
4.5*/
int d1, d4;
float d2, d5;
char d3;
System.out.print("Enter the numbers: ");
d1=sc.nextInt();
d2=sc.nextFloat();
d3=sc.next().charAt(0);
d4=sc.nextInt();
d5=sc.nextFloat();
System.out.println(d1);
System.out.println(d2);
System.out.println(d3);
System.out.println(d4);
System.out.println(d5);
--------------------------------------------------------------------
//34+78
int e1, e2, e;
System.out.print("Enter the two numbers: ");
e1= sc.nextInt();
e2=sc.nextInt();
e= e1 + e2;
System.out.println(e);
--------------------------------------------------------------------
//23-6
int f1, f2, f;
System.out.print("Enter the two numbers: ");
f1= sc.nextInt();
f2=sc.nextInt();
f= f1 - f2;
System.out.println(f);
--------------------------------------------------------------------
//45*2
int g1, g2, g;
System.out.print("Enter the two numbers: ");
g1= sc.nextInt();
g2=sc.nextInt();
g= g1 * g2;
System.out.println(g);
--------------------------------------------------------------------
//56/2
int h1, h2, h;
System.out.print("Enter the two numbers: ");
h1= sc.nextInt();
h2=sc.nextInt();
h= h1 / h2;
System.out.println(h);
--------------------------------------------------------------------
//45+78+23+12
int i1 , i2, i3, i4, i;
System.out.print("Enter the four numbers: ");
i1= sc.nextInt();
i2=sc.nextInt();
i3= sc.nextInt();
i4=sc.nextInt();
i= i1 + i2 + i3 + i4;
System.out.println(i);
--------------------------------------------------------------------
//56*34+12/2-13
int j1 , j2, j3, j4, j5, j;
System.out.print("Enter the five numbers: ");
j1= sc.nextInt();
j2=sc.nextInt();
j3= sc.nextInt();
j4=sc.nextInt();
j5=sc.nextInt();
j= j1 * j2 + j3/ j4 - j5;
System.out.println(j);
--------------------------------------------------------------------
//1.2*6.7-4.5/2
float k1, k2, k3, k;
int k4;
System.out.print("Enter the four operands: ");
k1= sc.nextFloat();
k2= sc.nextFloat();
k3= sc.nextFloat();
k4= sc.nextInt();
k = k1 * k2 - k3 / k4;
System.out.println(k);
--------------------------------------------------------------------
//1.6*(12-2)/2+7.8-1.5
float l1, l4, l5, l;
int l2, l3;
System.out.print("Enter the five operands: ");
l1= sc.nextFloat();
l2= sc.nextInt();
l3= sc.nextInt();
l4= sc.nextFloat();
l5= sc.nextFloat();
l = l1 * (l2-l3) / l3 + l4 - l5;
System.out.println(l);
--------------------------------------------------------------------
//4.5*1.2-(82/2)-5.6 +1.234
float m1, m2, m5, m6, m;
int m3, m4;
System.out.print("Enter the six operands: ");
m1= sc.nextFloat();
m2= sc.nextFloat();
m3= sc.nextInt();
m4= sc.nextInt();
m5= sc.nextFloat();
m6= sc.nextFloat();
m = m1 * m2 - (m3/m4) - m5 + m6;
System.out.println(m);
--------------------------------------------------------------------
//8*1+(4-2)/1+6
int n1, n2, n3, n4, n5, n;
System.out.print("Enter the five numbers: ");
n1= sc.nextInt();
n2=sc.nextInt();
n3= sc.nextInt();
n4=sc.nextInt();
n5=sc.nextInt();
n = n1 * n2 + (n3-n4) / n2 + n5;
System.out.println(n);
--------------------------------------------------------------------
//3.4+1.2*(3.7-1.2)/2+6.8
float o1, o2, o3, o5, o;
int o4;
System.out.print("Enter the five numbers: ");
o1= sc.nextFloat();
o2= sc.nextFloat();
o3= sc.nextFloat();
o4= sc.nextInt();
o5= sc.nextFloat();
o = o1 + o2 * (o3-o2) / o4 + o5;
System.out.println(o);
--------------------------------------------------------------------
//8.9*1.67-(6.21-5.6)+7.8-34 +157
float p1, p2, p3, p4, p5, p;
int p6, p7;
System.out.print("Enter the seven numbers: ");
p1= sc.nextFloat();
p2= sc.nextFloat();
p3= sc.nextFloat();
p4= sc.nextFloat();
p5= sc.nextFloat();
p6= sc.nextInt();
p7= sc.nextInt();
p = p1 * p2 - (p3-p4)+ p5 - p6 + p7;
System.out.println(p);
}
}