tcs_xplore_java_hands_on_2021 | java iteration hands on 1:finding the lowest valued charachter in the string
question:
write the main method in solution class.
the method will take the string as input and
print the minimum valued charachter in that string
(as per ascii value)
input: HellO
output:H
as H is having the lowest ascii value.
answer:
import java.util.Scanner;
public class solution {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String a=sc.nextLine();
int temp=(int)a.charAt(0);
for (int i = 1; i <a.length() ; i++) {
if((int)a.charAt(i)<temp)
{
temp=(int)a.charAt(i);
}
}
System.out.println((char)temp);
}
}
Comments
Post a Comment