-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassiment 1.java
More file actions
107 lines (82 loc) · 2.38 KB
/
assiment 1.java
File metadata and controls
107 lines (82 loc) · 2.38 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
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
Aditya Agarawal
Assignment 1
Q1 Write a java program to insert 3 numbers from keyboard and findout greater number among 3 numbers.
ANS
package insert3num;
import java.util.Scanner;
public class insert3num {
public static void main(String[] args) {
// TODO Auto-generated method stub
int a,b,c, lar;
Scanner sc= new Scanner(System.in);
System.out.println("Enter the first number:");
a = sc.nextInt();
System.out.println("Enter the second number:");
b = sc.nextInt();
System.out.println("Enter the third number:");
c = sc.nextInt();
lar = c > (a > b ? a : b) ? c : ((a > b) ? a : b);
System.out.println("The largest number is: "+lar);
}
}
Q2 Write a java program to find out the sum of command line argument.
package cmdline;
public class cmdline {
public static void main(String[] args) {
int c= Integer.parseInt(args[0]);
int d= Integer.parseInt(args[1]);
// TODO Auto-generated method stub
int s=c+d;
System.out.println("sum is"+s);
}
}
Q3 Write a program to demostrate static variables,methods and blocks.
package static1;
public class staic1 { static int a = 3;
static int b;
static void meth(int x) {
System.out.println("x = " + x);
System.out.println("a = " + a);
System.out.println("b = " + b);
}
static {
System.out.println("Static block initialized.");
b = a * 4;
}
public static void main(String[] args) {
meth(42);
}
}
Q4
package room;
import java.util.Scanner;
public class room {
Scanner s= new Scanner (System.in);
int roomno,roomarea;
String roomtype,acmachine;
void setdata()
{
System.out.println("Enter the room no");
roomno=s.nextInt();
System.out.println("Enter the room type");
roomtype=s.next();
System.out.println("Enter the room area");
roomarea=s.nextInt();
System.out.println("is room has AC or NOT");
acmachine=s.next();
}
void display()
{System.out.println(" room no"+roomno);
System.out.println(" room type"+roomtype);
System.out.println(" room area"+roomarea);
System.out.println("AC MACHINE"+acmachine);
}
public class rom{
}
public static void main(String[] args) {
// TODO Auto-generated method stub
room s1=new room();
s1.setdata();
s1.display();
}
}