Data Structure (2) - Stack Application (Digital Converter)

zhaozj2021-02-16  61

/ **

*

Title: Stack Application ---- You can perform transformation class between all values ​​ *

Description: *

Copyright: CopyRight (C) 2004 *

company: * @Author shaokun305 * @version 1.0 * /

Public class test1 {

Public Static String Changenumeric (String AASTR, INT N, INT M) {// Transform into 10

INT AA = 0; STRING RESULT = ""; stack stack = new stack (); string mmx = AASTR.TOUPPERCASE (); int endint = 0; for (int i = 0; i

//System.out.println ("mid=" mid);

// system.out.println ("MMX.Charat (i) =" mmx.charat (i)); int JINT = 0;

Switch (MMX.Charat (i)) {

Case 'a': jint = 10;

Break;

Case 'b': jint = 11;

Break;

Case 'c': jint = 12;

Break;

Case 'd': jint = 13;

Break;

Case 'E': JINT = 14;

Break;

Case 'f': jint = 15;

Break;

DEFAULT:

Jint = integer.parseint ("" mmx.charat (i));

}

Endint = Endint Jint * MID;

//System.out.println ("Endint=" Endint);

}

AA = Endint;

// AA now saves 10 credits

// The loop is taking the rest, and the stack is performed.

While (aa! = 0) {

Stack.push (new integer); aa / = m;

}

// Sports the integer value obtained,

While (! stack.isempty ()) {

INT J = ((Integer) stack.pop ()). INTVALUE (); String JSTR = ""; switch (j) {

Case 10: jstr = "a";

Break;

Case 11: jstr = "b";

Break;

Case 12: jstr = "c";

Break;

Case 13: jstr = "d";

Break;

Case 14: jstr = "e";

Break;

Case 15: JSTR = "f";

Break;

DEFAULT:

JSTR = "" J;

}

Result = JSTR;

}

// Output conversion results

Return Result; //system.out.println ("Result=" Result);

//System.out.println (new java.util.date ());}

Public test1 () {}

Public static void main (string [] args) {system.out.println (new java.util.date ()); test1 testx = new test1 (); string result = "; stack stack = new stack (); if (args.lendhe> = 3) {

INT AA = 0; // INTEGER.PARSEINT (Args [0]); int n = integer.parseint (args [1]); int m = integer.parseint (args [2]); / * / transformation into 10 system

String mmx = args [0] .touppercase (); int endint = 0; for (int i = 0; i

//System.out.println ("mid=" mid);

// system.out.println ("MMX.Charat (i) =" mmx.charat (i)); int JINT = 0; switch (mmx.charat (i)) {

Case 'a': jint = 10;

Break;

Case 'b': jint = 11;

Break;

Case 'c': jint = 12;

Break;

Case 'd': jint = 13;

Break;

Case 'E': JINT = 14;

Break;

Case 'f': jint = 15;

Break;

DEFAULT:

Jint = integer.parseint ("" mmx.charat (i));

}

Endint = Endint Jint * MID;

//System.out.println ("Endint=" Endint);

}

AA = Endint;

// AA now saves 10 credits

// The loop is taking the rest, and the stack is performed.

While (aa! = 0) {

Stack.push (new integer); aa / = m;

}

// Sports the integer value obtained,

While (! stack.isempty ()) {

INT J = ((Integer) stack.pop ()). INTVALUE (); string jstr = ""; switch (j) {case 10: jstr = "a";

Break;

Case 11: jstr = "b";

Break;

Case 12: jstr = "c";

Break;

Case 13: jstr = "d";

Break;

Case 14: jstr = "e";

Break;

Case 15: JSTR = "f";

Break;

DEFAULT:

JSTR = "" j;}

Result = JSTR;

} * /

Result = TEST1.CHANGENUMERIC (Args [0], N, M);

}

// Output conversion results

System.out.println ("Result =" result);

System.out.println (new java.util.date ());}}

# You compile this TEST1 class, if you use JDK, you can use Javac Test1.java and then then then: Java Test1 210145 10 16 Enter: Tue Apr 20 11:50:43 CST 2004 // Start Time Result = 334E1TUE APR 20 11 : 50: 43 CST 2004 // End Time Meaning: Transform Ten Binary 210145 to 16 Entering: 334E1 Re-Test: Java Test1 4D7A8F 16 2 Output: Tue Apr 20 11:54:44 CST 2004Result = 1001101011101010001111Tue APR 20 11 : 54: 44 CST 2004 Meaning: Transfer 16-Bao 4D7A8F into 2-based 100110101111101010001111

# Specific use stack conversion algorithm description: For example (1348) 10 = (2504) 8, the operation process is as follows N n Div 8 N MOD 8 1348 168 4 168 21 0 21 2 5 2 0 2

转载请注明原文地址:https://www.9cbs.com/read-15586.html

New Post(0)