![]() |
![]() |
#1 (permalink) |
Buffering.........
Location: Wisconsin...
|
[java] problem with return statement and placement of {}'s
Ok here is what I have in my Test class
Code:
package a4; /** * <p>Title: Assignment 4</p> * <p>Description: CS 161 Assignment 4 </p> * <p>Copyright: Copyright (c) 2004</p> * <p>Company: UW-River Falls</p> * @author Eric Merker * @email ericmerker@centurytel.net * @date started: Novemeber 9th 2004 finished: ???? * @team prometheusfree.org crew visit us at irc.shadowfire.org at #prometheus * @version 1.0 */ import javax.swing.*; public class Test { public Test() { } public static void main(String[] args) { Test test1 = new Test(); int x = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter a number")); } } Code:
/** * <p>Title: Assignment 4</p> * <p>Description: CS 161 Assignment 4 </p> * <p>Copyright: Copyright (c) 2004</p> * <p>Company: UW-River Falls</p> * @author Eric Merker * @email ericmerker@centurytel.net * @date started: Novemeber 9th 2004 finished: ???? * @team prometheusfree.org crew visit us at irc.shadowfire.org at #prometheus * @version 1.0 */ import javax.swing.*; public class Convert { public void print(int x); int printPower = x; {{ //missing an open {, and a return type on this line if (paraMeter > 12) System.out.println("Does not compute"); switch (x) { case 1: System.out.println("Ten"); break; case 2: System.out.println("Hundred"); break; case 3: System.out.println("Thousand"); break; case 4: System.out.println("Ten Thousand"); break; case 5: System.out.println("Hundred Thousand"); break; case 6: System.out.println("Million"); break; case 7: System.out.println("Ten Million"); break; case 8: System.out.println("Hundred Million"); break; case 9: System.out.println("Billion"); break; case 10: System.out.println("Ten Billion"); break; case 11: System.out.println("Hundred Billion"); break; case 12: System.out.println("Trillion"); break; }}}
__________________
Donate now! Ask me How! Please use the search function it is your friend. Look at my mustang please feel free to comment! http://www.tfproject.org/tfp/showthread.php?t=26985 |
![]() |
![]() |
#2 (permalink) |
Insane
Location: Wales, UK, Europe, Earth, Milky Way, Universe
|
I dont usually do people's homework for them, especially when the attempt looks pretty appauling like this. But, i'm a softy and i need the practice so... does this help:
Code:
import javax.swing.*; public class Convert { private int x; public Convert(int x) { this.x = x; } public void print { if (x > 12) { System.out.println("Does not compute"); } else { switch (x) { case 1: System.out.println("Ten"); break; case 2: System.out.println("Hundred"); break; case 3: System.out.println("Thousand"); break; case 4: System.out.println("Ten Thousand"); break; case 5: System.out.println("Hundred Thousand"); break; case 6: System.out.println("Million"); break; case 7: System.out.println("Ten Million"); break; case 8: System.out.println("Hundred Million"); break; case 9: System.out.println("Billion"); break; case 10: System.out.println("Ten Billion"); break; case 11: System.out.println("Hundred Billion"); break; case 12: System.out.println("Trillion"); break; } } } }
__________________
There are only two industries that refer to their customers as "users". - Edward Tufte |
![]() |
![]() |
#3 (permalink) |
Über-Rookie
Location: No longer, D.C
|
Get in the habit of indenting properly ;p Proper indention makes it so easy to spot missing brackets or too many brackets.
pretty much, if you ever have more than one { or } on a line you should work on your formatting. Otherwise you will hit a snag and it will be harder to spot. This comment is mainly for you at the beginning, until you get used to matching up your { } without thinking |
![]() |
Tags |
java, placement, problem, return, statement |
|
|