Vous êtes sur la page 1sur 7

a.

) public class Numberpattern { public static void main(String[] args) { for (int i=1; i<=3; i++) { for (int j=1; j<=i; j++) { System.out.print(i); } System.out.println(""); }

} }

c.) public class Numberpattern { public static void main(String[] args) { for (int i=3; i>=1; i--) { for (int j=1; j<=i; j++) { System.out.print(j); } System.out.println(""); }

} }

Facorial public class Factorial { public static void main(String[] args) { int number = 5; int factorial = number; for(int i =(number - 1); i > 1; i--) { factorial = factorial * i; } System.out.println("Factorial of number "+ number +" is " + factorial); } }

Anagram import java.util.Scanner; import java.util.*; public class Anagram2 {

public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter first word: "); String firstWord = input.next(); System.out.print("Enter second word: "); String secondWord = input.next(); firstWord.toLowerCase(); secondWord.toLowerCase(); char Array1[]; char Array2[]; Array1 = firstWord.toCharArray(); Array2 = secondWord.toCharArray(); for (int x = 0; x < Array1.length - 1; x++) { for (int y = x + 1; y < Array1.length; y++) { if (Array1[x] > Array1[y]) {

char temp = Array1[x]; Array1[x] = Array1[y]; Array1[y] = temp; } } }

for (int x = 0; x < Array2.length - 1; x++) { for (int y = x + 1; y < Array2.length; y++) { if (Array2[x] > Array2[y]) { char temp = Array2[x]; Array2[x] = Array2[y]; Array2[y] = temp; } } } if (Array1 == Array2) { System.out.println("The inputs are Anagrams"); } else { System.out.println("The inputs are not anagrams of each other"); } } } }

import java.util.Scanner; import java.util.*; /** * * @author Administrator */ public class Anagram2 { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Scanner input = new Scanner(System.in); System.out.print("Enter first word: "); String firstWord = input.next(); System.out.print("Enter second word: "); String secondWord = input.next(); firstWord.toLowerCase(); secondWord.toLowerCase(); char Array1[]; char Array2[]; Array1 = firstWord.toCharArray(); Array2 = secondWord.toCharArray(); for (int x = 0; x < Array1.length - 1; x++) { for (int y = x + 1; y < Array1.length; y++) { if (Array1[x] > Array1[y]) { char temp = Array1[x]; Array1[x] = Array1[y]; Array1[y] = temp; } } }

for (int x = 0; x < Array2.length - 1; x++) { for (int y = x + 1; y < Array2.length; y++) { if (Array2[x] > Array2[y]) { char temp = Array2[x]; Array2[x] = Array2[y];

Array2[y] = temp; } } } if (Array1 == Array2) { System.out.println("The inputs are Anagrams"); } else { System.out.println("The inputs are not anagrams of each other"); } } } }

public class Commission { /** * @param args the command line arguments */ public static void main(String[] args) { double sales = 1000; int Rate = 5; double cRate = .05; double commission =0;

commission = compute(sales,Rate); System.out.println(" commission" + commission); commission = compute(sales,cRate); System.out.println(" commission" + commission); } public static double computecommission(double s, int r) { return ( s * (r/100.)); } public static double compute(double s, double cr) { return ( s * cr); }

public static void main(String[] args) { private static Scanner scanner = new Scanner(System.in); int max; int min; int input; System.out.print("Enter a number: "); input = scanner.nextInt(); max = input; min = input; while(input != -99) { System.out.print("Enter a number: "); input = scanner.nextInt(); max = input > max ? input : max; min = input < min ? input : min; } System.out.println("max: " + max); System.out.println("min: " + min); }

Vous aimerez peut-être aussi