-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCh1_PracticeSet.java
More file actions
52 lines (42 loc) · 1.67 KB
/
Ch1_PracticeSet.java
File metadata and controls
52 lines (42 loc) · 1.67 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
import java.util.Scanner;
public class Ch1_PracticeSet{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Question 1: Write a program to Sum three number.
// int a = 3, b = 2, c = 5,sum;
// sum = a + b + c;
// System.out.println(sum);
// Question 2: Write a program to calculate cgpa using marks of three subjects(out of 100).
// float Subject1 = 45;
// float Subject2 = 95;
// float Subject3 = 48;
// float totalmarks = Subject1 + Subject2 + Subject3;
// float average = totalmarks/300*100;
// float Cgpa = average/10;
// Another Method:
// float Cgpa = totalmarks/30;
// System.out.println(average);
// System.out.println(Cgpa);
// Question 3: Write a program which asks the user to enter his/her name and greets them with "Hello <name>, have a good day" text.
// System.out.println("Enter your name:");
// String name = sc.next();
// System.out.println("Hello " +name+ " ,Have a Good Day");
// Qusetion 4: Write a program to convert Kilometer to meter -> therefor 1km = 1000m
// System.out.println("Enter Kilometer that you Convert to meter:");
// float km = sc.nextFloat();
// float meter = km * 1000;
// System.out.println(meter);
// Question 5: Write a program to detect whether a number is entered by the user is Integer or Not.
System.out.println("Enter any Number:");
//boolean num = sc.hasNextInt();
// System.out.println(num);
// Another Method:
boolean num;
if(num = sc.hasNextInt()){
System.out.println(num+" it is an Integer Datatype number");
}
else{
System.out.println(num+" it is an Another Datatype number");
}
}
}