0% found this document useful (0 votes)
17 views4 pages

Java String and Math Operations

Uploaded by

hallthen.olls
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views4 pages

Java String and Math Operations

Uploaded by

hallthen.olls
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

import java.util.

Scanner;

public class finalExam4{

public static void main (String[]args){

//use PI

double radius=5;

double area= Math.pow(radius,2)*Math.PI;

System.out.println(area);

// use Exponent

System.out.println(Math.sqrt(4));

System.out.println(Math.pow(2,2));

//use round

System.out.println(Math.ceil(4.2));

System.out.println(Math.floor(-3.6));

System.out.println(Math.rint(5.3));

System.out.println(Math.sqrt(4));

//use min max round‫عدد من صفر الى التسعه‬

System.out.println((int)+(Math.random()*10));

System.out.println(50+(int)(Math.random()*50));

//use Escape char

System.out.println("\"good morning\"");

//use String methods

String S1="Good Day\n";

System.out.println(S1.length());

System.out.println(S1.charAt(5));

System.out.println("Bay".concat(S1));

System.out.println(S1.toUpperCase());

System.out.println(S1.trim());
//Reading a String

Scanner input=new Scanner(System.in);

System.out.println("Enter name");

String name=input.next();

System.out.println("Welcom"+name);

//use equal

String x="Ali" , y="ali";

if(x.equals(y))

System.out.println("equals");

else

System.out.println("Not equals");

//use comparingTo

int num=x.compareTo(y);

if(num>0)

System.out.println("x greater then y");

else if (num<0)

System.out.println("x less then y");

else

System.out.println("x equals y");

//use startsWith

String s1="Ali" , s2="ali";

if(s1.startsWith("al"))

System.out.println("yes");

else

System.out.println("No");

//use endWith

String s3="Ali" , s4="ali";

if(s3.endsWith("li"))

System.out.println("yes");
else

System.out.println("Not");

//use contains

String s5="Ali" , s6="ali";

if(s3.contains("li"))

System.out.println("yes");

else

System.out.println("Not");

//use substring .take letter form 7 to the end

String z="khalid Ali ALharbi";

String sub= z.substring(7);

System.out.println(sub);

//use substring .take letter form 9 to the

String A="khalid Ali ALharbi";

String s= A.substring(7,9+1);

System.out.println(s);

//USE indexOf

String b="Abdullah Khalid Alharbi";

int loc=b.indexOf("a");

System.out.println(loc);

int loc2=b.indexOf("a",loc+1);

System.out.println(loc2);

//use lastIndexOf

String N="Abdullah Khalid Alharbi";

int loc3=N.lastIndexOf("i");

System.out.println(loc3);

int loc4=N.indexOf("i",loc-1);
System.out.println(loc4);

You might also like