|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming | |
Calling all Java/ Comp Sci Guru's
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |||||||||||
|
4.0 GHz
|
So I have no errors, but when I try to run after building this code, It does nothing? Any reason why? I am using netbeans to write my code, I know this is real basic but its my assignment. This is my code, +reps for help!
package jamesmills; import javax.swing.JOptionPane; import java.util.Scanner; public class jamesmills { public static void main(String[] args) { Scanner input = new Scanner(System.in); int Choice; float Num1, Num2; //numbers JOptionPane.showInputDialog (null, "Enter your first Number"); Num1=input.nextFloat(); JOptionPane.showInputDialog (null, "Enter your second Number"); Num2=input.nextFloat(); //choice JOptionPane.showInputDialog (null, "1.Addtion\n2.Subtraction\n.Multiplication\n.Divis ion\n5.Quit"); Choice=input.nextInt(); //decision while (Choice!=5) { switch (Choice) { case 1: addNumbers(Num1,Num2); break; case 2: subNumbers(Num1,Num2); break; case 3: multiNumbers(Num1,Num2); break; case 4: divideNumbers(Num1,Num2); break; case 5: break; }//end switch }//end while }//end void main //methods for math public static float addNumbers(float Num1, float Num2) { float Total; Total=Num1+Num2; return Total; } public static float subNumbers(float Num1, float Num2) { float Total; Total=Num1-Num2; return Total; } public static float multiNumbers(float Num1, float Num2) { float Total; Total=Num1*Num2; return Total; } public static float divideNumbers(float Num1, float Num2) { float Total; Total=Num1/Num2; return Total; } }//end class
__________________
92% of teens have moved on to rap. If you are part of the 8% who still listen to real music, copy and paste this
|
|||||||||||
|
|
|
|
|
#2 (permalink) | ||||||||||||
|
Programmer
![]() |
The Scanner reads from the standard input (and waits that you write something into the console), but the text entered into the JOptionPane isn't connected to the standard input.
__________________The function Code:
JOptionPane.showInputDialog (null, "Enter your first Number"); Code:
String result = JOptionPane.showInputDialog (null, "Enter your first Number"); Code:
int number = Integer.parseInt(result); Code:
Scanner scanner = new Scanner(result); int number = scanner.nextInt();
|
||||||||||||
|
|
|
|
|
#4 (permalink) | |||||||||||
|
4.0 GHz
|
great got it working thanks
__________________
92% of teens have moved on to rap. If you are part of the 8% who still listen to real music, copy and paste this
|
|||||||||||
|
|
|
|
|
#5 (permalink) | ||||||||||||||
|
Non generic awesome title
![]() |
I really wish we could preserve spacing on the forums....that was hard as hell to read >.<
__________________
Quote:
Case Mod: Silent Night Black's latest review: Need for Speed: Shift VS. Race Driver: Grid Alabama Overclocker >SELECT * FROM tblUsers WHERE clue > 0 0 rows returned
|
||||||||||||||
|
|
|
|
#6 (permalink) | ||||||||||||
|
4.0ghz
![]() |
Quote:
Code:
lsdkjf
lsdkjf
__________________
_₌=The Q9550 Club=₌_
1.16VID Q9550 @ 4.0Ghz (and counting) - 8k ppd GPU - GPUz-Validation Overclock.net Headphone Club: Because perfect hair is overrated. EP45-UD3P/R M.I.T. Template Team Fortress 2 Club
|
||||||||||||
|
|
|
|
#7 (permalink) | ||||||||||
|
AMD Overclocker
|
Hey dude, click "QUOTE" on my post and take everything from [quote] on down and edit your post. That was truly horrendous on the eyes.
__________________Quote:
|
||||||||||
|
|
|
|
|
#8 (permalink) | |||||||||||||
|
With great difficulty
![]() |
I think this is what you meant
__________________Code:
package jamesmills;
import javax.swing.JOptionPane;
import java.util.Scanner;
public class jamesmills
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int Choice;
float Num1, Num2;
//numbers
JOptionPane.showInputDialog (null, "Enter your first Number");
Num1=input.nextFloat();
JOptionPane.showInputDialog (null, "Enter your second Number");
Num2=input.nextFloat();
//choice
JOptionPane.showInputDialog (null, "1.Addtion\n2.Subtraction\n.Multiplication\n.Divis ion\n5.Quit");
Choice=input.nextInt();
//decision
while (Choice!=5)
{
switch (Choice)
{
case 1: addNumbers(Num1,Num2);
break;
case 2: subNumbers(Num1,Num2);
break;
case 3: multiNumbers(Num1,Num2);
break;
case 4: divideNumbers(Num1,Num2);
break;
case 5: break;
}//end switch
}//end while
}//end void main
//methods for math
public static float addNumbers(float Num1, float Num2)
{
float Total;
Total=Num1+Num2;
return Total;
}
public static float subNumbers(float Num1, float Num2)
{
float Total;
Total=Num1-Num2;
return Total;
}
public static float multiNumbers(float Num1, float Num2)
{
float Total;
Total=Num1*Num2;
return Total;
}
public static float divideNumbers(float Num1, float Num2)
{
float Total;
Total=Num1/Num2;
return Total;
}
}//end class
|
|||||||||||||
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|