473,398 Members | 2,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Java Exceptions

16
Hi,

Here is the code - The program does not provide any message to the user when no argument is pass

Expand|Select|Wrap|Line Numbers
  1. public class Hexnumbers{
  2.  
  3.  
  4.  public static int conv1(String s) 
  5.  throws NumberFormatException {
  6.  
  7.   String digits = "0123456789ABCDEF";
  8.     s = s.toUpperCase();
  9.    int val = 0;
  10.    for (int i = 0; i < s.length(); i++) {
  11.       char c = s.charAt(i);
  12.         int d = digits.indexOf(c);
  13.        val += d*Math.pow(16, s.length()-1-i);
  14.  
  15.   }
  16.        return val;
  17.  
  18.  
  19. }
  20.  
  21.  
  22.    public static String conv2(int d)
  23.    throws NumberFormatException
  24.  {
  25.        String digits = "0123456789ABCDEF";
  26.        if (d == 0) return "0";
  27.        String hex = "";
  28.        while (d > 0) {
  29.         int digit = d % 16;                
  30.            hex = digits.charAt(digit) + hex;  
  31.            d = d / 16;
  32.        }
  33.       return hex;
  34.    }
  35.  
  36.  
  37.  
  38.     public static void main(String[] args) {
  39.  
  40. try{
  41.         int sum = 0;
  42.  
  43.       for (int i = 0; i < args.length; i++) {
  44.         System.out.println(args[i]);
  45.  
  46.  
  47.  
  48.  
  49.   int decimal = conv1(args[i]);
  50.  
  51.  
  52.  
  53.    System.out.println("Here is the decimal number = "  +  decimal);
  54.    sum += decimal;
  55.  
  56.      String hex = conv2( decimal);
  57.        System.out.println("Here is the Hex number  = " + hex);
  58.  
  59.         System.out.println("Here is the sum of **Hex** + **Decimal** ==  "  + sum);
  60.    }
  61.  
  62.   }catch(NumberFormatException nfe) {
  63.         System.out.println ("Please Enter a valid argument");
  64.  
  65.     }
  66.  
  67.  
  68.     }
  69. }
  70.  
Nov 28 '07 #1
1 1358
JosAH
11,448 Expert 8TB
Hi,

Here is the code - The program does not provide any message to the user when no argument is pass
Yep, that is correct: you didn't tell it to do so,

kind regards,

Jos
Nov 28 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: BlackHawke | last post by:
Our program, game program Andromeda Online (www.andromedaonline.net) uses two programs- one to play the game, another to patch the game as updates come out. Players actually launch the updater...
6
by: Hung Jung Lu | last post by:
Hi, Just ran into this article http://www.mindview.net/Etc/Discussions/CheckedExceptions And I felt kind of reliefed. When I programmed in Java I always thought its usage of "checked...
7
by: Jan Gregor | last post by:
Hello I found that jython catches exact java exceptions, not their subclasses. Is there some way to get around this limitation (or error) ? My program has class representing database source...
133
by: Gaurav | last post by:
http://www.sys-con.com/story/print.cfm?storyid=45250 Any comments? Thanks Gaurav
4
by: Asfand Yar Qazi | last post by:
Consider the following operation: class C { public: ... virtual void override_me() = 0; struct AnException : public std::runtime_error { AnException(const std::string& arg)
458
by: wellstone9912 | last post by:
Java programmers seem to always be whining about how confusing and overly complex C++ appears to them. I would like to introduce an explanation for this. Is it possible that Java programmers...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
148
by: BillJosephson | last post by:
Want to do OOP. Does c++ have all the abilities of java, or is it some subset? Thanks...
20
by: mc | last post by:
I may be opening a can of worms and don't want to start a religious war, but... What features of Java do Java programmers miss when working in C#? Other than, of course, great portability. C#...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.