Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Other Java > Java GUI
|
Java GUI Discussions specific to programming Java GUI.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java GUI section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 8th, 2005, 05:53 PM
Registered User
 
Join Date: Sep 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Simple Java Program

Hi there,

I have the following program:

public class e1
{
    public static void main (String[] args){

    byte a = 1;
        while (a<9)
        {
            System.out.println(a);
            a++;
                 }
        }
}

When I try and compile the program I get the following error:

C:\Java\bookwork>javac e1.java
e1.java:8: possible loss of precision
found : int
required: byte
                a = a * 2;
                     ^
1 error

I know that changing the variable "a" from byte to int fixes this problem but how can I make this code work leaving "a" as a byte?

I hope someone can help

Kindest Regards
WargeMaster
 
Old September 9th, 2005, 12:25 PM
Authorized User
 
Join Date: Dec 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hello friend

here is your program. i use another variable and do casting for it to solve your problem and 'a' remains byte as well. so you can use both of them according to your need .If it does not solve your problem feel free to share your program idea with me.

public class e1
{
    public static void main (String[] args){

    byte a = 1;
        while (a<9)
        {
            System.out.println(a);
            a++;
    int ab = (int)a*2;
    System.out.println(ab);
                 }
        }
}

TAKE CARE


HumaMunir





Similar Threads
Thread Thread Starter Forum Replies Last Post
java program help chris1012 Java Basics 3 November 8th, 2007 09:35 AM
Simple assembly program runtime error vraifreud Visual C++ 2005 0 September 21st, 2007 01:20 AM
Simple Program Help hobbit666 Visual Basic 2005 Basics 2 December 19th, 2006 11:51 AM
java program todeepak_g JSP Basics 0 January 25th, 2006 06:04 AM
java program todeepak_g JSP Basics 0 January 25th, 2006 06:01 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.