You are on page 1of 4

QUESTION#01:

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


decrement (post and pre) on variables and display the result.
ANSWER:
  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);

QUESTION#02:
Write a java program of 7 string built-in functions and display.
ANSWER:
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication31;
import java.util.Scanner;
/**
*
* @author Qasim technology XD
*/
public class JavaApplication31 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String q = "Qasim";
int x= q.length();
System.out.println(x);
String y = q.toUpperCase();
System.out.println(y);
String z = q.toLowerCase();
System.out.println(z);
boolean a = q.startsWith("Qa");
System.out.println(a);
boolean b = q.endsWith("im");
System.out.println(b);
char c = q.charAt(1);
System.out.println(c);
String f = q.replace('Q', 'B');
System.out.println(f);
}
QUESTION#03:
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
ANSWER:
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