Tuesday, January 21, 2020

Converting Integers to Roman Numerals - Java


     Roman Number are a system of numerical notations used by the Romans.

1= I
5= V
10= X
50= L
100= C
500= D
1000= M = I
5000V
10,000X
50,000L
100,000C = I
500,000D = V
1,000,000M = X
5,000,000V = L
10,000,000X = C
50,000,000L = D
100,000,000 C = M
500,000,000 D
1,000,000,000M
nn = 1000×nnnn = 100,000×nnnn = 1,000,000×nn

                                                                                                                                                            























import java.util.*; class RomanCounting { public static void main(String[] args) { int num; System.out.println("please the number smallest than 999999"); System.out.println("According to automated program show 5000 as |V| and 10000 as |X| " + "and \n 50000 " + "as |L| and 100000 as |C| and 500000 as |D| and last as 1000000 as |M| "); Scanner obj = new Scanner(System.in); num = obj.nextInt(); String str = String.valueOf(num); char []arr = str.toCharArray(); int len = str.length(); int count[] = new int[10]; for(int i=0;i<len;i++){ count[i] = (int)arr[i]-48; } String ones[] = new String[]{"","I","II","III","IV","V","VI","VII","VIII","IX","X"}; String tens[] = new String[]{"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC","C"}; String hundred[] = new String[]{"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM","M"}; String thousand[] = new String[]{"","M","MM","MMM","MMMM","|V|","|V|M","|V|MM","|V|MMM", "M|X|","|X|"}; String TenThousand[] = new String[]{"","|X|","|X||X|","|X||X||X|","|X||L|","|L||X|", "|L||X||X|","|L||X||X|","|C||L|","|C|"}; String[] HundredThousand = new String[]{"","|C|","|C||C|","|C||C||C|","|C||D|","|D|", "|D||C|","|D||C||C|","|D||M|","|M|"}; if(len==6){ String romancounting = HundredThousand[count[0]]+ TenThousand[count[1]]+ thousand[count[2]] + hundred[count[3]] + tens[count[4]] + ones[count[5]]; System.out.println(romancounting); } else if(len==5){ String romancounting = TenThousand[count[0]]+ thousand[count[1]]+ hundred[count[2]] + tens[count[3]] + ones[count[4]]; System.out.println(romancounting); } else if(len==4){ String romancounting = thousand[count[0]]+ hundred[count[1]] + tens[count[2]] + ones[count[3]]; System.out.println(romancounting); } else if(len==3) { String romancounting = hundred[count[0]]+tens[count[1]]+ones[count[2]]; System.out.println(romancounting); } else if(len==2){ String romancounting = tens[count[0]]+ones[count[1]]; System.out.println(romancounting); } else{ System.out.println("Sorrt But number is invalid! OutOfRange👌"); } System.out.println("Thanks for using your automated software"); } }

For Output : OUTPUT

Friday, January 17, 2020

Count the Occurrence of Character in the Linked List

~ Create an array.
~ One By One place the  character on array  on based on ASCII Value .
~ then, check the value of every index and find greater value/Occurence of Character.
public class LinkedlistOperation {

 Node head;
     class Node{
        int data;
        Node next;
           Node(int d){
               data =d;
               next = null;
       }    }


 public void OccurrenceNumber(){
    Node current= head;
    int arr[] = new int[256];
    while(current!=null){
       (arr[current.data])++;
       current =current.next;
          }
    System.out.println("Occurrence of all character are :");

    for(int i=0;i<256;i++){
        if(arr[i]>0){
          System.out.println(i+":" +arr[i]+" ");
   } } }


 public static void main(String ...args){
 LinkedlistOperation list = new LinkedlistOperation();
   list.push(1);
   list.push(1);
   list.push(3);
   list.push(4);
   list.push(2);
   list.push(2);
   list.push(15);
   list.push(20);
   list.push(1);
   list.push(1);
   list.push(3);
   list.push(4);
   list.push(5);
  list.OccurrenceNumber()  }
 OUTPUT :

Occurence of all Character are :
1:4 
2:2 
3:2 
4:2 
5:1 
15:1 
20:1 


Thursday, January 16, 2020

Insertion Node in the Linkelist.

In this post, methods to insert a new node in linked list are discussed. A node can be added in three ways
1) At the front of the linked list
2) After a given node.
3) At the end of the linked list
public class Linkedlist {
 Node head;
 class Node{
  int data;
  Node next;
  Node(int d){
   data =d;
   next=null;
  } 
 }
// INSERT THE NODE AT THE BEGIN OF LINKEDLIST.

 
 public void insertAtfront(int new_data){
  
//  Node temp = head;
  Node new_node = new Node(new_data);
  new_node.next = head;
  head = new_node;
  
 } 
// INSERT THE NODE AT THE GIVEN POSITION IN LINKEDLIST.

 public void insertAtGiven(Node prev_node,int new_data)
 {
  if(prev_node == null){
   System.out.print("previous node can't be null");
   return;
   
  }
  Node new_node = new Node(new_data);
  new_node.next = prev_node.next;
  prev_node.next = new_node;
 }
// INSERT THE NODE  AT THE END OF THE LINKEDLIST.  

 public void insertAtEnd(int new_data){
  
  Node new_node = new Node(new_data);
  new_node.next = null;
  Node last = head;
  while(last.next!=null){
   last = last.next;
  
  }
  last.next= new_node;
  return;
  
 }
// TRAVERSING THE ELEMENT OF LINKEDLIST

 
 public void showlist(){
  Node tnode= head;
  while(tnode!=null){
   System.out.print(tnode.data+" ");
   tnode = tnode.next;
  }
 }
 // MAIN FUNCTION 

public static void main(String ...args) { list.insertAtfront(10); list.insertAtfront(12); list.insertAtfront(14); list.insertAtfront(16); list.insertAtfront(18); list.insertAtfront(19); list.insertAtGiven(12,20); list.insertAtGiven(20,22); list.insertAtEnd(24); list.showlist(); } }

Arrays in Solidity Programming Language.

Arrays Solidity supports both generic and byte arrays. It supports both fixed size and dynamic arrays. It also supports multidimensional ...