Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit970be08

Browse files
committed
Updated OctalToDecimal.java
1 parentb26b8f4 commit970be08

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

‎Conversions/OctalToDecimal.java

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,41 @@
77
*
88
*/
99
publicclassOctalToDecimal {
10-
10+
1111
/**
1212
* Main method
1313
*
14-
* @param args Command line arguments
14+
* @param args
15+
* Command line arguments
1516
*/
1617
publicstaticvoidmain(Stringargs[]) {
1718
Scannersc =newScanner(System.in);
18-
into =sc.nextInt();
19-
System.out.println("Decimal equivalent: " +convertOctalToDecimal(o));
19+
System.out.print("Octal Input: ");
20+
StringinputOctal =sc.nextLine();
21+
intresult =convertOctalToDecimal(inputOctal);
22+
if (result != -1)
23+
System.out.println("Result convertOctalToDecimal : " +result);
2024
sc.close();
2125
}
22-
26+
2327
/**
24-
* This method converts an octal number to
25-
* a decimal number.
28+
* This method converts an octal number to a decimal number.
2629
*
27-
* @param o The octal number
30+
* @param inputOctal
31+
* The octal number
2832
* @return The decimal number
2933
*/
30-
publicstaticintconvertOctalToDecimal(into) {
31-
System.out.print("Octal Input: ");
32-
// Read the input from the console which we are expecting as an octal number:
33-
Scanners =newScanner(System.in);
34-
StringinputHex =s.nextLine();
35-
try{
34+
publicstaticintconvertOctalToDecimal(StringinputOctal) {
35+
36+
try {
3637
// Actual conversion of Octal to Decimal:
37-
IntegeroutputDecimal =Integer.parseInt(inputHex,8);
38-
System.out.println("Decimal Equivalent : " +outputDecimal);
39-
}
40-
catch(NumberFormatExceptionne){
41-
//Printing a warning message if the input is not a valid octalnumber:
38+
IntegeroutputDecimal =Integer.parseInt(inputOctal,8);
39+
returnoutputDecimal;
40+
}catch (NumberFormatExceptionne) {
41+
// Printing a warning message if the input is not a valid octal
42+
// number:
4243
System.out.println("Invalid Input, Expecting octal number 0-7");
43-
}
44-
finally{
45-
s.close();
44+
return -1;
4645
}
4746
}
4847
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp