• Log in or sign up for an account here: https://www.sythe.org/login

Javculator v0.1 by 1337snak3

  • Thread starter Thread starter 1337Snak3
  • Start date Start date
1

1337Snak3

Guest
okay, if you dont know what this is, it's calculator.
If u've done anything in java u can use this.
I hope u get along with my english in the program...

Code:
import java.util.Scanner;
// sythe.org 1337Snak3
public class Javculator {
	public static void main(String[] args) throws Exception {
		Scanner skanneri = new Scanner(System.in);

		System.out.println("please,type the first number(s) example 53 or 8 or anything like that,press enter");
		int a = skanneri.nextInt();
		System.out.println("Now, the second number(s),press Enter");
		int b = skanneri.nextInt();
		System.out.println("Now,type what you wanna do about the numbers you earlier gave, 1 for plus 2 for minus 3 for times or what do they ever call it and 4 for the example 28/7 = 4 things ");
		int c = skanneri.nextInt();
		double x = a;
		double y = b;
		int res1 = a+b;
		int res2 = a-b;
		int res3 = a*b;
		double res4 = x/y;

		while (c != 0) {
			switch (c) {
				case 1:
				System.out.println(a + " plus "+ b +" is :"+ res1);
				break;
				case 2:
				System.out.println(a + " minus "+ b +" is :"+ res2);
				break;
				case 3:
				System.out.println(a + " times "+ b +" is :"+ res3);
				break;
				case 4:
				System.out.println(a + " shared "+ b +" is :"+ res4);
				break;
				default:
				System.out.println(" Are you sure you gave a number 1-4 when asking what you want to do?");
			}
			System.out.println("now, you can change the way to calculate if you wish to.");
			c = skanneri.nextInt();
		}
	}
}
 
Nice program - just thought i'd tell you there's an easier way to get user input using JOptionPane.

Read about showInputDialog in the java api. :)
 
why instantiate x to a when u already have a?
why not just instantiate "a" as a double and forget about x. Not wrong, just a question of mine.
 
Well, i thought that it's there just incase... maybe not needed...
 
Well, i thought that it's there just incase... maybe not needed...

System.out.println("please,type the first number(s) example 53
+ or anything like that,press enter ");
int a = skanneri.nextInt();
System.out.println("Now, the second number(s),press Enter");
int b = skanneri.nextInt();
double x = a;
double y = b;

if you instantiate a as a int, whats the point of converting it to a double if its value wont have any decimal places anyways? Wouldn't it avoid a lot of trouble to initially instantiate a as a double? Maybe he didn't know that theres a "skanneri.nextDouble()" ?

(no offence to what you wrote...im just trying to learn more about the language itself still)
 
good for a starter ... try making it better by using GUI and stuff , i dont feel like looking thru all my files right now, but earlier i made a GUI calc thats alot better then the one that comes with windows =\

--Aut0er
Edit:
i would also make it alot more user friendly
Code:
System.out.println("ENTER EQUATION");
String something = scanner.in;
String[] r = something.split(" ");
int firstnum = r[0];
int secondnum  = r[2];
String todo = r[1];
switch todo...
case "+"
add
case "-"
subtract
case "x"
multiply
case"/"
divide
that code is obviously not complete but it will let the user enter stuff such as "5 + 5"
 
Wait so we take that code (edit it a bit) post it in TextPad and then save as .java or what.... Sry for noobie question new to JAVA =\
 
Wait so we take that code (edit it a bit) post it in TextPad and then save as .java or what.... Sry for noobie question new to JAVA =\

yep, i suggest downloading "BlueJ"
download, select "start new project" and ull be set from there...its like using hightech notepad with java grammar check.
 
Thanks, I'll be needing this code as a reference once I start on my own calculator.
 
duelarena.gg
Back
Top