mathajax

Java program String char into Ascii and Generate multiplication tables.

 String char to ASCII value Conversion

 The program read s string from user and converts each of the character from string into ascii value using for loop statement and byte type casting.

On beginning of the program execution, a string input read from user to convert into ascii char by char.   



import java.util.Scanner;

public class String2Ascii {

    public static void main(String[] args) 
     {
  
 System.out.println("string char to Ascii value  n" );    
 Scanner sc =new Scanner(System.in);  
  
 System.out.println("Enter a string" );  
 String str =sc.nextLine();
 sc.close();
     
     System.out.println("\nchar \t Ascii");
     for(int n=0;n<str.length() ; n++ ) 
     {
        char c = str.charAt(n); 
        System.out.println(c + " -t" + (byte)c); 
     }
     
    }

}


Output
string char to Ascii value  

Enter a string
hello world

char - Ascii
h - 104
e - 101
l - 108
l - 108
o - 111
  - 32
w - 119
o - 111
r - 114
l - 108
d - 100


 Generate Multiplication tables

 The program generate nth times tables. on executing program, user has to an input n times table to generate and for loop statement used to literately print table's row upto 10.

On beginning of the program execution, a integer input  read from user to generate a math multiplication table.that contains 10 rows.  



import java.util.Scanner;

public class Tables {

 public static void main(String[] args) 
 {       
    System.out.println("Multiplication Table n" );    
    Scanner sc =new Scanner(System.in);  
  
   System.out.println("Enter n times table to generate" );  
   int n =sc.nextInt();
   sc.close();
  
     System.out.println( n +" Times tables");     
    for(int i=1; i<=10; i++) 
      {
     String tblrow = n + " x " + i +" = " + (n*i);   
     System.out.println(tblrow);
      }
     
      }

}


Output
Multiplication Table 

Enter n times table to generate
6

6 Times tables

6 x 1 = 6
6 x 2 = 12
6 x 3 = 18
6 x 4 = 24
6 x 5 = 30
6 x 6 = 36
6 x 7 = 42
6 x 8 = 48
6 x 9 = 54
6 x 10 = 60

Comments

Popular posts from this blog

Solving System of Linear Equations by Gauss Jordan Elimination

Matrix Forward and Back Substitution

Solve System of Linear Equations by LU Decompose

Distance Metric - Euclidean Distance

Matrix Determinant by Upper Triangular Matrix