Java Tutorials
Armstrong Number Program in JAVA
What is Armstrong Number ? In an Armstrong Number, the sum of power of individual digits is equal...
In this tutorial, we will study programs to
There are multiple ways to convert a Char to String in Java. In fact, String is made of Character array in Java. Char is 16 bit or 2 bytes unsigned data type.
We can convert String to Character using 2 methods -
public class CharToString_toString {
public static void main(String[] args) {
//input character variable
char myChar = 'g';
//Using toString() method
//toString method take character parameter and convert string.
String myStr = Character.toString(myChar);
//print string value
System.out.println("String is: " + myStr);
}
}
String is: g
public class CharToString_valueOf {
public static void main(String[] args) {
char myChar = 'g';
//valueOf method take character parameter and convert string.
String myStr = String.valueOf(myChar);
////print string value
System.out.println("String is: " + myStr);
}
}
String is: g
//Convert String to Character using string method
package com.gtupapers;
public class StringToChar {
public static void main(String[] args)
{
//input String
String myStr = "gtupapers";
//find string length using length method.
int stringLength =myStr.length();
//for loop start 0 to total length
for(int i=0; i < stringLength;i++)
{
//chatAt method find Position and convert to character.
char myChar = myStr.charAt(i);
//print string to character
System.out.println("Character at "+i+" Position: "+myChar);
}
}
}Character at 0 Position: G Character at 1 Position: u Character at 2 Position: r Character at 3 Position: u Character at 4 Position: 9 Character at 5 Position: 9
What is Armstrong Number ? In an Armstrong Number, the sum of power of individual digits is equal...
What is Interface? The interface is a blueprint that can be used to implement a class. The...
What is the C++ language? C++ is a computer programming language that contains the feature of C...
What is Polymorphism in Java? Polymorphism in Java occurs when there are one or more classes or...
What is indexOf() Method in Java? indexOf() Method is used to get index of the first occurrence of a...
What is Exception in Java? Exception in Java is an event that interrupts the execution of program...