Home » All posts
Saturday, September 15, 2012
Hex Value Decimal Value
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
A 10
B 11
C 12
D 13
E 14
F 15
. .
. .
so on ...........
Maximum Number (Retrieve Maximun Number Of Array)
8:03 PM Marianz
public class MaximumNumber
{
public static void main(String[] args)
{
int[] numbers = {3,4,5,7};
int max = 0;
for(int i=0;i<numbers.length;i++)
{
if(numbers[i] > max)
{
max = numbers[i];
}
}
System.out.println("Max Number In Array : " + max);
}
}
EvenOdd-Number (Determine Even-Odd Number - Try Catch Handler)
7:52 PM Marianz
import java.io.*; public class EvenOddNumber{ public static void main(String[] args) throws IOException{ try{ int n; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter Number : "); n = Integer.parseInt(in.readLine()); if (n % 2 == 0){ System.out.println("Given number is Even."); }else{ System.out.println("Given number is Odd."); } }catch(NumberFormatException e){ System.out.println(e.getMessage() + " is not a numeric value."); System.exit(0); } } }
Anagrams ( Creating Anagrams -Entered Words )
7:35 PM Marianz
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: Consolas, "Courier New", Courier, Monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #a31515; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
import java.io.*; public class Anagrams { public static void main(String[] args)throws IOException { BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter a string:"); String s = r.readLine(); char[] text = new char[s.length()]; for (int i=0; i<s.length(); i++) { text[i] = s.charAt(i); } System.out.println("Here are all the anagrams of " + s); printAnagrams(text, 0); } public static void printAnagrams(char[] a, int i) { if (i == a.length-1) printArray(a); else { for (int j=i; j< a.length; j++) { //swap a[i] with a[j] char c = a[i]; a[i] = a[j]; a[j] = c; printAnagrams(a, i+1); //swap back c = a[i]; a[i] = a[j]; a[j] = c; } } } static void printArray(char [] a) { for (int i=0; i< a.length; i++) System.out.print(a[i]); System.out.println(); } }
Subscribe to:
Posts
(
Atom
)