Skip to content

Commit 2717b9f

Browse files
Create 23.2 Basic Class Object.java
1 parent 68a5a48 commit 2717b9f

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

23.2 Basic Class Object.java

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
Write a program to print the names of students by creating a Student class. If instead of name some other data type is passed then the name should be "Unknown", otherwise the name should be equal to the String value passed while creating object of Student class.
3+
4+
Input Format
5+
6+
Rahul 33
7+
8+
Constraints
9+
10+
Use constructor with argument to initialize the name
11+
Create an object with name to print the name of the student
12+
Pass Two inputs such as one is name and the other with different data type
13+
Output Format
14+
15+
Rahul Unknown
16+
17+
Sample Input 0
18+
19+
Rahul
20+
33
21+
Sample Output 0
22+
23+
Rahul
24+
Unknown*/
25+
import java.io.*;
26+
import java.util.*;
27+
import java.text.*;
28+
import java.math.*;
29+
import java.util.regex.*;
30+
31+
class Student
32+
{
33+
String s1,s2;
34+
Student(String x,String y)
35+
{
36+
if((x.toUpperCase()).equals(x.toLowerCase()))
37+
{
38+
s1 = "Unknown";
39+
}
40+
else
41+
s1 = x;
42+
if((y.toUpperCase()).equals(y.toLowerCase()))
43+
{
44+
s2 = "Unknown";
45+
}
46+
else
47+
s2 = y;
48+
}
49+
}
50+
public class Solution {
51+
52+
public static void main(String[] args) {
53+
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
54+
Scanner sc = new Scanner(System.in);
55+
String s1 = sc.nextLine();
56+
String s2 = sc.nextLine();
57+
Student s = new Student(s1,s2);
58+
System.out.println(s.s1);
59+
System.out.println(s.s2);
60+
61+
}
62+
}

0 commit comments

Comments
 (0)