Java H/w

Questions about programming languages and debugging
Post Reply
User avatar
isapiens
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 533
Joined: 05 May 2006, 16:00
14
Location: Turn around

Java H/w

Post by isapiens »

Hey guys, i havent posted around here for so long... I have school now and its so busy, but i still read the posts though ;)

I got a little question. I was doing this coding problem which is really easy. Basically u gota draw a calculator that can add to numbers. You draw the calculator in the promt so u dont need any GUI.

here is the code:

Code: Select all

import java.util.Scanner; //Needed for the scanner class

public class Calculator
	{
		public static void main (String[]args)
			{
double num_1;   		//declare number 1
double num_2;		//declare number 2
double SUM;			//declare the SUM
Scanner kbd = new Scanner(System.in);

num_1 = kbd.nextDouble();
num_2 = kbd.nextDouble();
SUM = num_1 + num_2;
System.out.println("     ---------------------      ");
System.out.println("  |    ----------------     |   ");
System.out.printf ("  | |%14d | |\n", SUM       );
System.out.println("  |    ----------------     |   ");
System.out.println("  |                             |   ");
System.out.println("  |   7     8     9    +     |   ");
System.out.println("  |                             |   ");
System.out.println("  |   4     5     6    -      |   ");
System.out.println("  |                              |   ");
System.out.println("  |   1     2     3    *      |   ");
System.out.println("  |                              |   ");
System.out.println("  |   0           =    /       |   ");
System.out.println("  |                              |   ");
System.out.println("     ---------------------      ");
}

}
...................................

The only line that doesnt work is this one:

Code: Select all

System.out.printf ("  | |%14d | |\n", SUM       );
They told us to just copy and paste it so the value gets outputed on the right side of that box(the calculator screen)
But it gives me an error. I am doing this on windows java, while in class its in linux and the teacher said you might have problems if u dont do it on linux machine... But i dont know if thats the problem. tx
ps(its due 2ow)[/code]

User avatar
isapiens
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 533
Joined: 05 May 2006, 16:00
14
Location: Turn around

Post by isapiens »

Anyway, i realized that that line only works for integer values, but not double. I hate how i was not told that in the assignment. I still dont know why u have to use integers to make that line work :( At least i got it working.

Post Reply