Skip to content

Commit c053a13

Browse files
committed
Initial commit
0 parents  commit c053a13

File tree

5 files changed

+112
-0
lines changed

5 files changed

+112
-0
lines changed

First.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public class First{
2+
// We have static keyword in the main function cause we want to execute the main function without creating an object of Main class.
3+
public static void main(String[] args){
4+
// String args[] stores the values given in the terminal as string
5+
// System.out.println("Hello Saniel");
6+
System.out.println(args[0]);
7+
}
8+
}
9+
// Package is a folder in which the java file lies

Inputs.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import java.util.Scanner;
2+
3+
public class Inputs{
4+
public static void main(String[] args) {
5+
Scanner sc = new Scanner(System.in);
6+
// Scanner is a class and sc is the object of the class and we are initializing the constructor of the Scanner class
7+
// System.out.println() --> in the standard output stream print something
8+
// System.in ==> take the input from keyboard whenever input is asked
9+
int input = sc.nextInt(); // nextInt()--> it will take an integer value as a input.
10+
String input1 = sc.next(); // it will take string value till space comes
11+
// if we want to take complete sentence then use nextLine() instead of next().
12+
System.out.println(input);
13+
System.out.println(input1);
14+
}
15+
}

Primitives.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import java.util.Scanner;
2+
3+
public class Primitives{
4+
public static void main(String[] args){
5+
// There are roughly 6 primitive datatypes
6+
//int, float, double, long, char, boolean
7+
// int num = 10;
8+
// float marks = 98.67f;
9+
// double largeDecimalNumber = 234345.3453453;
10+
// long largeInteger = 234234234234234L;
11+
// char myChar = 'A';
12+
// boolean check = true;
13+
Scanner sc = new Scanner(System.in);
14+
15+
// int roll = sc.nextInt();
16+
// System.out.println(roll);
17+
18+
// String name = sc.nextln();
19+
// System.out.println(name);
20+
21+
// float marks = sc.nextFloat();
22+
// System.out.printf(marks);
23+
24+
// double x = sc.nextDouble();
25+
// System.out.println(x);
26+
27+
// long y = sc.nextLong();
28+
// System.out.println(y);
29+
30+
// Typecasting
31+
// int num = (int)56.89f;
32+
// System.out.println(num);
33+
34+
// Automatic type promotion in expression
35+
// int a = 257;
36+
// byte b = (byte)a; // Implicit conversion of int to byte
37+
// // a byte can store 256 values so when we are storing the value 257
38+
// // 257 is too big for byte so 257 % 256 = 1 is stored
39+
// // So the value of byte becomes 1
40+
// System.out.println("Value of Byte : " + b);
41+
42+
// byte a = 40;
43+
// byte b = 50;
44+
// byte c = 100;
45+
46+
// int d = (a * b) / c; // while performing the multiplication operation it easily exceeds the value that can be stored in a byte datatype
47+
// // Thus, while doing the intermediate operations the byte data is converted into integer datatypes which makes these operations possible
48+
// System.out.println(d);
49+
50+
byte b = 47;
51+
char d = 'a';
52+
short s = 1098;
53+
int j = 78373;
54+
float h = 5.87f;
55+
double k = 0.123456;
56+
double result = (h * b) + (j/d) - (k - d);
57+
System.out.println((h * b) + " " + (j/d) + " " + (k - d));
58+
System.out.println(result);
59+
60+
}
61+
}

Temperature.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import java.util.Scanner;
2+
3+
public class Temperature{
4+
public static void main(String[] args){
5+
Scanner sc = new Scanner(System.in);
6+
System.out.println("Enter the temperature in Celsius: ");
7+
float celsius = sc.nextFloat();
8+
float fahrenheit = (celsius * 9/5) + 32;
9+
System.out.printf("%f degrees Celsius is %.2f degree fahrenheit:", celsius, fahrenheit);
10+
}
11+
}

loops.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
public class loops{
2+
public static void main(String[] args){
3+
// int count = 1;
4+
// while(count<=5){
5+
// System.out.println(count);
6+
// count++;
7+
// }
8+
9+
// Use while loop when you dont know how many times the loop is going to run
10+
// Use for loop when you know how many times the loop is going to run
11+
12+
// for(int i = 0; i<5; i++){
13+
// System.out.println(i+1);
14+
// }
15+
}
16+
}

0 commit comments

Comments
 (0)