In mathematics , the factorial of a non-negative integer n , denoted by n !, is the product of all positive integers less than or equal to n . For example, The value of 0! is 1, according to the convention for an empty product import java.util.Scanner; public class Factorial { public static void main(String[] args) { int num ,fact=1; System.out.println("enter number:"); Scanner sc=new Scanner(System.in); num=sc.nextInt(); if(num<0){ System.out.println("only positive number !"); } else{ for(int i=1;i<=num;i++) { fact=fact*i; } System.out.println("the factorial of "+num + " is " +fact); } } } Output: ======= enter number: 3 the factorial of 3 is 6
Posts
The String class represents character strings . All string literals in Java programs, such as "abc" , are implemented as instances of this class. Strings are constant; their values cannot be changed after they are created. String buffers support mutable strings . Because String objects are immutable they can be shared. Reading a String < import java.util.Scanner; public class ReadString { public static void main(String[] args) { System.out.println("enter a String: "); Scanner sc =new Scanner(System.in); while(true){ String s=sc.nextLine(); s=s.toLowerCase(); if(s.indexOf("hari")!=-1){ System.out.println("Hi,hari!"); } else{ System.out.println("Who are you?"); } break; } } } OutPut: Enter a String: hari Hi,hari!
Repetition of character in a String import java.util.Scanner; public class A { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter the String : "); String value = sc.nextLine(); //System.out.println(); System.out.print("Enter the Charcter : "); String ch = String.valueOf((sc.next().charAt(0))); int count=0; for(int i=0;i<value.length();i++) { if((String.valueOf(value.charAt(i))).equalsIgnoreCase(ch)) { count++; } } System.out.println("The character : "+ ch +" is present "+count+" times"); } } Output : Enter the String : hello Enter the Charcter : l The character : l is present 2 times
Program to find count of vowels and consonant import java.util.Scanner; public class Vowel { public static void main(String[] args) { System.out.println("enter a string:"); Scanner sc=new Scanner(System.in); String v=sc.nextLine(); int len=v.length(); char[] vw={'a','e','i','o','u'}; int count=0; for(int i = 0 ; i< len;i++) { for(int j = 0; j<5;j++) { if((String.valueOf(v.charAt(i))).equalsIgnoreCase((String.valueOf(vw[j])))) { count++; } } } System.out.println("In this String there are "+count+" vowels and "+(len-count)+" consonant."); } }
1.//Program to write reverse a string public class Reverse { public static void main(String[] args) { String s="abcd"; String rs=""; for (int i=s.length()-1;i>=0;i--){ rs=rs+s.charAt(i); } System.out.println(s); System.out.println(rs); } } OutPut : abc cba 2. Using StringBuffer(String string) method, reverse the buffer and then converts the buffer into a String with the help of toString() public class StringReverseExample{ public static void main(String[] args){ String string="abcdef"; String reverse = new StringBuffer(string). reverse().toString(); System.out.println("\nString before reverse: "+string); System.out.println("String after reverse: "+reverse); } } 3. Another public class Reverse { public String reverseString(String s){ if (s.length()<=1){ return s; } else
Issued by Engineers & Architects after earthquake group (http://on.fb.me/1zJqpHC) Plaster Cracks Below 10 mm. Material : Doctor Fixit Crack ‘X’ Paste Procedure : 1. First cut the crack with ‘V’ Shape 2. Clean the crack area. 3. Moisture the crack area. 4. Apply the crack paste by running hand. 5. Leave it by
Learning Adobe Photoshop is quite easy. We finds so many video tutorials in the youtube.com for all level. We can do what ever we want provided that we must know basic and some good practice . Creative minds are always active Adobe Photoshop Requirement: Creative minds Enthusiastic Adobe Photoshop software Practice Practice Practice Practice
#. Why do we have 8 Primitive data type? Based on type and range of data , primitive types are divided into 8 types. #. Why do we have 4 referenced data type? To collect same type of values of Array is given and to collect different type of values class,interface and enum are given. JVM creates memory location based on the data type size,names that ML with the given name,and stores the assigned value in the memory location . This named memory location is technically called variable. Example: class DataTypesDemo{ //primitive type variable creation byte b =10; int i =20; char ch ='a'; //Array type variable creation double[] d ={1,2,3,4,5}; //predefined class string type variable creation String str = "Hari"; public static void main(String [] args) { </br> //User defined class DataTypeDemo variable
For the most commonly used data types, Java provides the following base types (also called primitive types): boolean a boolean value: true or false char 16-bit Unicode character byte 8-bit signed two’s complement integer short 16-bit signed two’s complement integer int 32-bit signed two’s complement integer long 64-bit signed two’s complement integer float 32-bit floating-point number (IEEE 754-1985) double 64-bit floating-point number (IEEE 754-1985)
1. Computing is part of everything we do! Computing and computer technology are part of just about everything that touches our lives from the cars we drive, to the movies we watch, to the ways businesses and governments deal with us. Understanding different dimensions of computing is part of the necessary skill set for an educated person in the 21st century. Whether you want to be a scientist, develop the latest killer application, or just know what it really means when someone says “the computer made a mistake”, studying computing will provide you with valuable knowledge. 2. Expertise in computing enables you to solve complex, challenging problems. Computing is a discipline that offers rewarding and challenging possibilities for a wide range of people regardless of their range of interests. Computing requires and develops capabilities in solving deep, multidimensional problems requiring imagination and sensitivity to a variety of concerns. 3. Computing enables you to m
If you have been using Eclipse with ADT , be aware that Android Studio is now the official IDE for Android, so you should migrate to Android Studio to receive all the latest IDE updates. To migrate existing Android projects, simply import them using Android Studio: In Android Studio, close any projects currently open. You should see the Welcome to Android Studio window. Click Import Non-Android Studio project . Locate the project you exported from Eclipse, expand it, select the build.gradle file and click OK . In the following dialog, leave Use gradle wrapper selected and click OK . (You do not need to specify the Gradle home.)