In: Computer Science
Implement a function that will change the very first symbol of the given message to uppercase, and make all the other letters lowercase.
2. Implement a function that will compute the area of a triangle.
Ques 1)
package string.manipulation;
import java.util.Scanner;
public class StringManipulation {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in); //object to take input
System.out.println("Enter message");
String str = sc.nextLine(); // taking input
String output = str.substring(0, 1).toUpperCase() + str.substring(1).toLowerCase(); // changing message to proper format
System.out.println("Corrected Message: " + output); // printing result
}
}
Output:-
Ques 2)
package areaoftriangle;
import java.util.Scanner;
public class AreaOfTriangle {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in); // object to take input
System.out.println("Enter height of triangle");
int h = sc.nextInt(); //height of triangle
System.out.println("Enter base of triangle");
int b = sc.nextInt(); // base of triangle
//area of triangle = (h*b) / 2
System.out.println("Area of Triangle: " + h*b/2);
}
}
Output:-
In the first program predefined String function is used to convert each alphabet of string to lower and upper case.
Second program calculates the area of triangle on the basis of it's height and base.
Note:- Please comment down if you face any problem. :)