Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > General Coding
You last visited: Today at 21:12

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Problem mit Java :o

Discussion on Problem mit Java :o within the General Coding forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Sep 2011
Posts: 2
Received Thanks: 0
Problem mit Java :o

Hallo Community,ich lerne grade Java eclipse und wollte einen "mini Taschenrechner" machen... DOch es tritt andauernd folgender Fehler auf : Exception in thread "main" java.lang.Error: Unresolved compilation problem:

at Cl.main(Cl.java:5)



Hier ist der Text den ich geschrieben Habe : import java.util.Scanner;


public class Cl {
public static void main(String args[]) {
Scanner s = new Scanner (System.in);

int x,y,z;

System.out.println("Bitte 2 Zahlen eingeben");

x = s.nextInt();
y = s.nextInt();

z = x+y;
System.out.println("Die Summe aus " + x +" und " + y + "ist" + z);

}
}
}


Hoffe einer kann mir helfen.
MfG PaNiiC
pαɴιιcхrυlez is offline  
Old 10/19/2011, 13:16   #2
 
elite*gold: 0
Join Date: Nov 2007
Posts: 62
Received Thanks: 17
Code:
import java.util.Scanner;

public class Rechner
{
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int x, y, z;
		
		System.out.println("Bitte 2 Zahlen eingeben: ");
		
		x = scanner.nextInt();
		y = scanner.nextInt();
		
		z = x + y;
		System.out.println("Die Summe aus " + x + " und " + y + " ist " + z);
	}
}
Demon-777 is offline  
Thanks
1 User
Old 10/19/2011, 14:11   #3
 
XxharCs's Avatar
 
elite*gold: 34
Join Date: Apr 2011
Posts: 1,475
Received Thanks: 1,228
Code:
import javax.swing.JOptionPane;

public class Rechner
{
    public static void main(String[] args)
    {
        String eing1, eing2;
        int zahl1, zahl2;
        eing1 = JOptionPane.showInputDialog(null,"Erste Zahl eingeben:");
        eing2 = JOptionPane.showInputDialog(null,"Zweite Zahl eingeben:");
        zahl1 = Integer.parseInt(eing1);
        zahl2 = Integer.parseInt(eing2);

        int su,di,pr;
        float qu;

        su = zahl1 + zahl2;
        di = zahl1 - zahl2;
        pr = zahl1 * zahl2;
        qu = zahl1 % zahl2;

        JOptionPane.showMessageDialog(null, "Die Summe von " +  zahl1
               + " und " + zahl2 + " ergibt " + su + ".");
        JOptionPane.showMessageDialog(null, "Die Differenz von " + zahl1
               + " und " + zahl2 + " ergibt " + di + ".");
        JOptionPane.showMessageDialog(null, "Das Produkt von " + zahl1
               + " und " + zahl2 + " ergibt " + pr + ".");
        JOptionPane.showMessageDialog(null, "Der Quotient von " + zahl1
               + " und " + zahl2 + " ergibt " + qu + ".");
    }           
}
XxharCs is offline  
Thanks
1 User
Old 10/19/2011, 15:53   #4
 
elite*gold: 0
Join Date: Oct 2011
Posts: 12
Received Thanks: 1
Hier hast mal einen "Mini-Taschenrechner" alerdings mit einer Grafischen Oberfläche. Vielleicht bringt er dir was

Ich weiß er sieht nicht gerade berauschend aus ...^^

Code:
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class APanel extends Panel implements ActionListener{

	
	private GridLayout g1;
	private Button a;
	private Button d;
	private Button c;
	private Button e;
	private Panel p1;
	private TextField tf;
	private TextField tf1;
	private TextField tf2;
	private TextField tf3;

	public APanel() {
		g1 = new GridLayout(5,2);
		p1 = new Panel(g1);

		tf1 = new TextField();
		tf2 = new TextField();
		tf3 = new TextField();

		a = new Button("Addieren");
		d = new Button("Subtrahieren");
		c = new Button("Multiplizeiren");
		e = new Button("Dividieren");

		a.addActionListener(this);
		d.addActionListener(this);
		c.addActionListener(this);
		e.addActionListener(this);




		p1.add(tf1);
		p1.add(a);
		p1.add(tf2);
		p1.add(d);
		p1.add(tf3);
		p1.add(c);
		p1.add(new Panel());
		p1.add(e);


		this.add(p1);

	}
	@Override
	public void actionPerformed(ActionEvent arg0) {


		Button b = (Button) arg0.getSource();   
		if(b == a){

			double z1 = Double.parseDouble(tf1.getText());
			double z2 = Double.parseDouble(tf2.getText());
			tf3.setText(new Double(z1+z2).toString());

		}
		if(b== d) {

			double x1=Double.parseDouble(tf1.getText());
			double x2=Double.parseDouble(tf2.getText());
			tf3.setText(new Double(x1-x2).toString());
		}
		if(b == c) {

			double z1 = Double.parseDouble(tf1.getText());
			double z2 = Double.parseDouble(tf2.getText());
			tf3.setText(new Double(z1*z2).toString());
		}
		if(b == e) {

			double y1 = Double.parseDouble(tf1.getText());
			double y2 = Double.parseDouble(tf2.getText());
			if(y2==0){
				tf3.setText("Divison durch 0 nicht erlaubt");
			}
			else{
				tf3.setText(new Double(y1/y2).toString());
			}
		}
	}
}
mfg
nekii3 is offline  
Thanks
1 User
Old 10/20/2011, 06:55   #5
 
Kinu's Avatar
 
elite*gold: 10
Join Date: May 2006
Posts: 2,786
Received Thanks: 773
Quote:
Originally Posted by pαɴιιcхrυlez View Post
DOch es tritt andauernd folgender Fehler auf : Exception in thread "main" java.lang.Error: Unresolved compilation problem:

at Cl.main(Cl.java:5)


Also dein Code selbst läuft bei mir. Du hast blos eine } am Ende zuviel.
Kinu is offline  
Thanks
1 User
Old 10/21/2011, 09:49   #6
 
elite*gold: 0
Join Date: Sep 2011
Posts: 2
Received Thanks: 0
Ok Danke leute
pαɴιιcхrυlez is offline  
Reply


Similar Threads Similar Threads
Java ?! Problem
10/10/2011 - Minecraft - 3 Replies
Also ich hatte vor 2 Tagen ein problem mit einer Mc mod danach hatte ich Java noch mal neu installiert und da kam das Problem : Als ich Java neu installiert hatte hat sich Minecraft nichtmehr geöffnet und das mit der .bat Datei klappt auch nicht als ich eine Systeniederherstellung versucht hatte ging Minecraft Immernoch nicht und wenn ich auf die Java Homepage gehe schmiert der Browser ab aber er schließt sich einfach ohne Fehlermeldung . Was kann ich tuhen
Java Problem...
05/21/2011 - Technical Support - 9 Replies
Hey Com. , Suche jemanden der sich gut mit Java auskennt. Ich kann Java nicht "Deinstallieren" und "Minecraft" kann ich nicht starten. Wer mir helfen kann,bitte in Skype melden.
Java Problem
02/27/2011 - Minecraft - 5 Replies
Minecraft stürtzt nach ein paar Minuten immer wieder ab hier der ErrorLog # # A fatal error has been detected by the Java Runtime Environment: # # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x4ee1f1f5, pid=4048, tid=4196 # # JRE version: 6.0_24-b07 # Java VM: Java HotSpot(TM) Client VM (19.1-b02 mixed mode windows-x86 ) # Problematic frame:
Java Problem
01/23/2011 - Technical Support - 8 Replies
Hey Leute Ich habe heute meinen Laptop( W7 64 bit) auf werkzustand zurückgesetzt. Dann kamen die Standart Programme: ICQ,Firefox,Skype und Java. Bei Java gab es ein Problem. Ich habe mir 3 verschiedene Versionen von der Homepage heruntergeladen (darunter auch die 64 bit version) Und jedesmal kam die Fehlermeldung,dass das Instalations paket nicht existiert bzw. darauf nicht zugreifen kann obwohl ich admin bin. Please Help
Java Problem
01/13/2011 - Minecraft - 9 Replies
Hallo ich will mich mit nem server verbinden dann kommt dieses Problem: Connection Lost Internal Expextion: Java.io.UTDDataFormatException:malformed input around byte5



All times are GMT +1. The time now is 21:13.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.