You are on page 1of 2

Q1: Write a program in java to Implement Increment (post and pre) and

decrement (post and pre) on variables and display the result.


  int a = 5;
        int b = 2;
        int c;
        int d;
        c = ++b; // pre increment
        d = a++; // post increment
        c++; // post increment
        System.out.println("a = " + a + " b = " + b + " c = " + c + " d = " + d);
    

Q2: Write a java program of 7 string built-in functions and display.


String greeting = "Hello!"; greeting.length();
String greeting = "Hello"; greeting.equals("Hello");
greeting.equals("Good-Bye");
String greeting = “mary!"; greeting.equalsIgnoreCase("Mary!") ;
String greeting = "Hi Mary!"; greeting.toLowerCase();
String greeting = "Hello!"; greeting.charAt(0);
String sample = "AbcdefG"; sample.substring(2);

Q3: Write a program that inputs radius and use’s choice. It calculates area of
circle if user enters 1as choice. It calculates circumference of circle if user enters 2
as a choice. Use switch statement
import java.util.Scanner;
public class JavaApplication11 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the radius: ");
double radius = sc.nextDouble();
System.out.println("Enter 1 for area ");
System.out.print("Enter 2 for circumference ");
int input = sc.nextInt();
switch (input) {
case 1:
double area = 3.14 * (radius * radius);
System.out.println("The area of circle is: " + area);
break;
case 2:
double circumference= 3.14 * 2*radius;
System.out.println( "The circumference of the circle is:"+circumference) ;
break;
}
}

You might also like