this site is to help students to learn coding in java platform and qbasic platform. all programs are ICSE and ISC level. Java programs java python Python programs
Hexadecimal to Decimal
import java.util.Scanner;
class HexaDecimalToDecimal
{
public static void main(String args[])
{
String hexdec ;
String hex= "0123456789ABCDEF";
Scanner sc = new Scanner(System.in);
System.out.print("Enter Hexadecimal Number : ");
hexdec = sc.nextLine();
hexdec = hexdec.toUpperCase();
int decimal = 0;
for (int i = 0; i < hexdec.length(); i++)
{
char ch = hexdec.charAt(i);
int in= hex.indexOf(ch);
decimal = 16*decimal + in;
}
System.out.print("Decimal Number is " + decimal);
}
}
String Encode In Java
An encoded string can be decoded by finding actual character for the given ASCII code in the encoded message. Write a program to input anencoded text having only
sequence of ACSII values without any spaces.Any code or value which is not in the range(65-90 or 97-122 or 32 for space) will be ignored and should not appear in the output message.Decode the encoded text and print in the form of sentence.The first alphabet of each word must be in capitals and rest alphabets will be in lower case
only. Any consecutive sets of code 32 will be taken as only one blank space.
The output should be exactly in the following format:
Input (encoded string) : 10665771011153266797868
Output(decoded string) : James Bond
Input (coded string) : 78487367421013232321006589
Output(decoded string) : Nice Day
Coding:
import java.lang.*;
class de_code
{
public static void main(String[]args)throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String code=br.readLine();
int c=0;
String k="";
while(c<code.length())
{
char s=code.charAt(c);
if (s!='1')
{
String S1= code.substring(c,c+2);
int p=Integer.parseInt(S1);
char p1= (char)p;
if((p1>='a' && p1<='z')||(p1>='A' && p1<='Z')||(p1==32))
k=k+p1;
c+=2;
}
else
{
String S1= code.substring(c,c+3);
int p=Integer.parseInt(S1);
char p1= (char)p;
k=k+p1;
c+=3;
}
}
String z=k.toLowerCase();
char w=z.charAt(0);
char x=Character.toUpperCase(w);
String y=x+z.substring(1);
System.out.println(y.replaceAll("\\s+"," "));
}
}
Comment
Subscribe to:
Posts (Atom)
Second largest number in java using ternary operator
//Largest second number using ternary operator public class Main { public static void main(String[] args) { int a=5,b=6,c=7; int ...
-
import java.util.*; class riwi { public static void main(String[]args) { Scanner sc=new Scanner(System.in); System...
-
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 ...
-
import java.io.*; class snowball { public static void main()throws IOException { BufferedReader br = new BufferedReader(new InputStreamRead...