Skip to content

more programs for the beginners #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
9ed94e2
Create inputoutput.java
gamixaqua Oct 13, 2017
f1161da
Merge pull request #2 from gamixaqua/master
chinmoy159 Oct 13, 2017
1017578
Create classobject.java
gamixaqua Oct 13, 2017
1194e4f
Update classobject.java
gamixaqua Oct 13, 2017
a77d046
Update and rename inputoutput.java to input_output/inputoutput.java
chinmoy159 Oct 15, 2017
f1a930f
Rename inputoutput.java to java_io_II.java
chinmoy159 Oct 15, 2017
ceca0ec
Merge pull request #3 from gamixaqua/master
chinmoy159 Oct 15, 2017
50d216c
Create java_io_I.java
chinmoy159 Oct 15, 2017
b8adc98
Update java_io_I.java
chinmoy159 Oct 15, 2017
0dc6d34
Update and rename classobject.java to class_and_objects/class_object.…
chinmoy159 Oct 15, 2017
e60b025
Create selection_sort.java
chinmoy159 Oct 18, 2017
475e033
selection sorting
chinmoy159 Oct 18, 2017
5b64042
Create bubble_sort.java
chinmoy159 Oct 18, 2017
3ca9502
bubble_sort
chinmoy159 Oct 18, 2017
8724ca2
insertion_sorting
chinmoy159 Oct 18, 2017
2771ae3
Create merge_sort.java
chinmoy159 Oct 18, 2017
11e8cd4
Create Selection_Statements.java
gamixaqua Oct 18, 2017
ec41045
merge_sort
chinmoy159 Oct 18, 2017
33e84ef
Merge pull request #4 from gamixaqua/patch-1
chinmoy159 Oct 18, 2017
2422d44
Create loops.java
gamixaqua Oct 18, 2017
78e10da
Merge pull request #5 from gamixaqua/patch-2
chinmoy159 Oct 19, 2017
df6e7b5
updated the file
chinmoy159 Oct 19, 2017
9281296
corrected the readme
Oct 24, 2017
4037491
rectification
Oct 24, 2017
a2591e4
Merge pull request #6 from jackdaw14-9/master
chinmoy159 Oct 24, 2017
07e81f3
quick_sorting
Oct 24, 2017
b01d737
generic_sorting
Oct 24, 2017
72f2848
Merge pull request #7 from jackdaw14-9/master
chinmoy159 Oct 24, 2017
9727b09
binary_exponentiation
Oct 25, 2017
42d8778
binary_exponentiation_multiplication
Oct 25, 2017
f32bb00
Euclidean_GCD_method
Oct 25, 2017
811376f
Merge pull request #8 from jackdaw14-9/master
chinmoy159 Oct 25, 2017
40fc2e5
counting_set_bits_in_a_number
Oct 25, 2017
f6766a4
remainder_of_division
Oct 25, 2017
d9fbbdb
Merge pull request #9 from jackdaw14-9/master
chinmoy159 Oct 25, 2017
d45df85
infix to postfix
Oct 26, 2017
2d28ee6
basic map data structure
Oct 26, 2017
dad77de
example in Map
Oct 26, 2017
4bee854
Merge pull request #10 from jackdaw14-9/master
chinmoy159 Oct 26, 2017
4dc7827
Create pom.xml
Oct 16, 2018
1dc8cde
Merge pull request #11 from jackdaw14-9/master
chinmoy159 Oct 16, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Loops.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
public class Loops
{
public static void number(int x)
{
//using while loop
while (x < 10) {
++x;
System.out.println(x);
}
}
public static void even(int z)
{
do {
System.out.println (z);
z += 2;
} while (z <= 10);
}
public static void table(int y)
{
//using for loop
int i;
for (i = 1; i <= 10; ++i) {
System.out.println(i*y);
}
}
public static void main(String[] args)
{
System.out.println("Number from 1 to 10");
number(0);
System.out.println("Even Numbers between 0 to 10");
even(0);
System.out.println("Table of 8");
table(8);
}
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Java-Guide-for-Beginners
This will be an Open Guide for all beginners in Python ! You can read and learn simple Java codes here , and whats more interesting is that you can even Contribute !!!
## This will be an Open Guide for all beginners in JAVA!
You can read and learn simple Java codes here , and whats more interesting is that you can even Contribute !!!
36 changes: 36 additions & 0 deletions Selection_Statements.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

package selectionstatements;


public class Selection_Statements {
public static String IfElse(int x){
if(x%2==0){
return "even";
}
else{
return "odd";
}
}
public static String Switch(int x){
switch(x){
case 1 :
return "it's one";
case 2 :
return "it's two";
case 3 :
return "it's three";
default:
return "out of my knowledge";
}
}


public static void main(String[] args) {
Selection_Statements obj = new Selection_Statements();
String y = obj.IfElse(123);
System.out.println("The number is "+ y);
String x=obj.Switch(2);
System.out.println("switch statements result is :"+ x);
}

}
27 changes: 27 additions & 0 deletions class_and_objects/class_object.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
public class class_object
{
//class declaration
public int square(int x)
{
return x*2;
}
public double square_rt (int x)
{
return Math.sqrt (x);
}
public static void main(String[] args)
{
// using the command line arguements as input
int x = Integer.parseInt (args[0]);

Class object = new Class(); // declaring an object for class Class

int y = object.square (x); // calling a method of class Class
double z = object.square_rt (x); // calling a method of class Class

System.out.println("Input number = " + x);
System.out.println("Square of number = " + y);
System.out.println("Square root of number = " + z);
}

}
106 changes: 106 additions & 0 deletions data_structures/infix_to_postfix.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import java.util.Scanner;
import java.util.StringTokenizer;

/**
* Program to convert infix expression to postfix.
* Input format :- there have to be spaces in between numbers and mathematical signs
* + - * / % ^ ( ) are considered.
* example of input :- a * b - c / d * ( e - f ) ^ g + h
* example of output :- a b * c d / e f - g ^ * - h +
*/
public class infix_to_postfix
{
public static int precedence(String sign)
{
switch (sign) {
case "+":
case "-":
return 0;
case "*":
case "/":
return 1;
case "%":
return 2;
case "^":
return 3;
case "(":
case ")":
return 4;
default:
return 5;
}
}

public static void main(String[] args)
{
String St, i;
Scanner Sc = new Scanner (System.in);
Stack stack = new Stack();
St = Sc.nextLine();
StringTokenizer obj = new StringTokenizer(St);
for (St = obj.nextToken(); obj.hasMoreTokens(); St = obj.nextToken()) {
if (St.equals("(")) {
stack.push (St);
continue;
}
if (St.equals(")")) {
for (i = stack.top(); !stack.is_empty(); stack.pop(), i = stack.top()) {
if (i.equals("(")) {
stack.pop();
break;
} else {
System.out.print(i + " ");
}
}
continue;
}
if (St.equals("+") || St.equals("-") || St.equals("*") || St.equals("/") || St.equals("%") || St.equals("^")) {
for ( ; !stack.is_empty(); ) {
i = stack.top();
if (i.equals("(")) {
break;
}
if (precedence (i) >= precedence (St)) {
System.out.print(i + " ");
stack.pop();
} else {
break;
}
}
stack.push (St);
} else {
System.out.print(St + " ");
}
}
System.out.print(St + " ");
for ( ; !stack.is_empty(); stack.pop()) {
System.out.print(stack.top() + " ");
}
}
}
class Stack {
private String[] arr;
private int size;
public Stack()
{
size = 0;
arr = new String[10000];
}
public String top()
{
return arr[size - 1];
}
public void pop()
{
--size;
}
public void push (String val)
{
arr[size] = val;
++size;
}
public boolean is_empty()
{
return size == 0;
}
}
63 changes: 63 additions & 0 deletions data_structures/maps_I.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class maps_I
{
public static void main(String[] args)
{
Map<Integer, String> my_map = new HashMap<Integer, String>();
Scanner Sc = new Scanner(System.in);
int choice;
String St; int key;
do {
choice = Sc.nextInt();
switch (choice) {
case 1:
// check
key = Sc.nextInt();
System.out.println(my_map.containsKey(key));
St = Sc.next();
System.out.println(my_map.containsValue(St));
break;
case 2:
// insert
// if key-value pair exists,
// then it replaces the existing pair with the new pair !
key = Sc.nextInt();
St = Sc.next();
my_map.put(key, St);
break;
case 3:
// get value
key = Sc.nextInt();
System.out.println(my_map.get(key));
break;
case 4:
// size
System.out.println(my_map.size());
break;
case 5:
// clear the map
my_map.clear();
break;
case 6:
// remove an element
key = Sc.nextInt();
System.out.println("Removed :- " + my_map.get(key));
my_map.remove(key);
break;
case 7:
System.out.println(my_map);
System.out.println(my_map.keySet());
System.out.println(my_map.entrySet());
break;
case 10:
System.exit(0);
break;
default:
System.out.println("Try Again");
}
} while (true);
}
}
34 changes: 34 additions & 0 deletions data_structures/maps_ex_1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;
/**
* java.util.HashMap is unordered.
* This class makes no guarantees as to the order of the map,
* in particular, it does not guarantee that the order will remain constant over time.
*
* java.util.LinkedHashMap uses insertion-order.
* This implementation differs from HashMap in that it maintains a doubly-linked list running through all of its entries.
* This linked list defines the iteration ordering,
* which is normally the order in which keys were inserted into the map (insertion-order).
*
* java.util.TreeMap, a SortedMap, uses either natural or custom ordering of the keys.
* The map is sorted according to the natural ordering of its keys,
* or by a Comparator provided at map creation time, depending on which constructor is used.
*/
public class maps_ex_1
{
public static void main(String[] args)
{
String St; Integer key;
int t;
Scanner Sc = new Scanner(System.in);
Map<String, Integer> my_map = new LinkedHashMap<String, Integer>();
for (t = Sc.nextInt(); t > 0; --t) {
St = Sc.next();
key = my_map.get(St);
my_map.put(St, (key == null) ? 1 : key + 1);
}
System.out.println(my_map.size());
System.out.println(my_map);
}
}
46 changes: 46 additions & 0 deletions input_output/java_io_I.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
public class java_io_I
{
public static void main(String[] args)throws IOException
// throw the Exception class object for input-output exceptions ie. IOException
{
InputStreamReader Isr = new InputStreamReader (System.in);
BufferedReader Br = new BufferedReader (Isr);

// all inputs are taken as Strings
// also the entire line is taken as input
// Now just parse the String into whichever data type required.

String input;
int input_i;
long input_l;
float input_f;
double input_d;
char input_c;

input = Br.readLine(); // Taking input as a String
System.out.println(input); // String Input

input = Br.readLine(); // Taking input as a String
input_i = Integer.parseInt (input); // parsing input
System.out.println(input_i);

input = Br.readLine(); // Taking input as a String
input_l = Long.parseLong (input); // parsing input
System.out.println(input_l);

input = Br.readLine(); // Taking input as a String
input_f = Float.parseFloat (input); // parsing input
System.out.println(input_f);

input = Br.readLine(); // Taking input as a String
input_d = Double.parseDouble (input); // parsing input
System.out.println(input_d);

input_c = (char) Br.read(); // Taking input as a character
Br = new BufferedReader (Isr); // flush the junk characters (of newline or carriage return) from the input buffer
System.out.println(input_c);
}
}
36 changes: 36 additions & 0 deletions input_output/java_io_II.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import java.util.Scanner;
//import this package for input

public class java_io_II
{
public static void main(String[] args) {
//for input
Scanner Sc = new Scanner(System.in);

// variable "input_x" takes the input for data type x

// for integer inputs
int input_i = Sc.nextInt();
System.out.println("Input = " + input_i);

// for Long_Integer inputs
long input_l = Sc.nextLong();
System.out.println("Input = " + input_l);

// for float inputs
float input_f = Sc.nextFloat();
System.out.println("Input = " + input_f);

// for double_float inputs
double input_d = Sc.nextDouble();
System.out.println("Input = " + input_d);

// for String inputs WORD by WORD
String input_St = Sc.next();
System.out.println("Input = " + input_St);

// for String inputs Entire Line
input_St = Sc.nextLine();
System.out.println("Input = " + input_St);
}
}
Loading