top of page

 

 

Java Iterations - Hands on 1

 

Write main method in Solution class.

 

The method will read a String value and print the minimum valued character (as per alphabet and ASCII sequence). 

 

 

 

Consider below sample input and output:

 

 

 

Input:

 

HellO

 

Output:

 

H

 

 

 

Important: Answer is not 'e' since 'H' has lower ASCII value then 'e'

 

Solutions:


import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
 public static void main(String args[] ) throws Exception {
 /* Enter your code here. Read input from STDIN. Print output to STDOUT */
 String str;
 Scanner scn=new Scanner(System.in);
 str=scn.next();
 int[] values=new int[str.length()];
 for(int i=0;i<str.length();i++)
 {
 values[i]=(int)(str.charAt(i));
 }
 int min=values[0];
 for(int i=0;i<values.length;i++)
 {
 if(values[i]<=min)
 min=values[i];
 }
 char c=(char)min;
 System.out.print(c);
 }
}

Java Iterations - Hands on 1: About

©2018 by The real one. Proudly created with Wix.com

bottom of page