Programing in java

Hey everyone :slight_smile:

Can anyone tell if I am missing something…

//Text-printing program. 

public class Welcome1
{
	//main method begins executiion of Java 
   public static void main( String args[] )
	{
		System.out.println( "Welcome to Java Programming!" ); // System.out.println( "Text" ) will print what's written within "", in this case it will print Welcome to Java Programming!
	 
	}   //end method main
	
} //end class Welcome1

This is save as Welcome1.java and to this printer in cmd I need to give the correct place which is C:\Users\Valentin\Documents\Programmera_i_Java\Java_source_file so I write in cmd

cd C:\Users\Valentin\Documents\Programmera_i_Java\Java_source_file

After writing java Welcome3 I get this

C:\Users\Valentin\Documents\Programmera_i_Java\Java_source_file>java Welc
Exception in thread "main" java.lang.NoClassDefFoundError: Welcome3
Caused by: java.lang.ClassNotFoundException: Welcome3
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: Welcome3.  Program will exit.

C:\Program Files\Java\jdk1.6.0_23\bin is the system enironment and I have made a special Folder called Programing in Java where C:\Users\Valentin\Documents\Programmera_i_Java\Java_source_file is added in Exclusions of Execution Control Settings and also in D+ rules as Trusted programs.

Thanks for all the help.

Regards,
Valentin N

I have learned a little Java but not much outside of it, like using it with CMD. (And I’ve forgotten a lot of Java, after messing with Python and now doing a web design course with HTML, CSS, and Javascript. I have focus issues. :P)

You may want to ask your question here: http://www.codeguru.com/forum/forumdisplay.php?f=5 or at another programming forum. After all, most people are here for security topics, not programming help. :wink:

thanks for the website and it’s mark so that I can ask there :slight_smile: I found my mistake which took me 2h… >:(

Are you teaching yourself with a course or taking one (in college?)?

I am teaching myself but I will have a course later.

Regards,
Valentin N

This is a good place too! all java

Also Don’t forget Brain.exe and VirtualMachine :stuck_out_tongue:

Jake

This is save as Welcome1.java
After writing java Welcome3 I get this

Please clarify… What is your class called, Welcome1 or Welcome3?

Welcome3. I have found the mistake this morning; I will highlight the mistake


public class Welcome3
{
   public static void main( String args[] )
	{
		System.out.println( "Welcome to Java Programming!" ); 

	 }
} //end class Welcome3

the right code


public class Welcome3
{
	
   public static void main( String args[] )
	{
		System.out.println( "Welcome\nto\nJava\nProgramming!" );
	 
	}   
	
} 

One thing that I notice after long time is that I need to double click on my java source file that puts javac.exe (java’s compiler) to create the wanted classes and the I should try to run the wanted class in cmd.

Thanks once again for all the help. It’s really appreciated

Regards,
Valentin N

Can anyone tell me what is wrong within this source code. Thanks in advance.


//Addition program that displays the sum of two number
import java.util.Scanner; // program uses class Scanner

public class Addition
{
	
	public static void main( String args[] )
	{
		Scanner input = new Scanner( System.in ); // create method to obtain input from command windows
	
		int number1; // First number to add
		int number2; // Second number to add
		int sum; // sum of number1 and number 2
	
		System.out.print( "Enter first integer: " ); // prompt
		number1 = input.nextInt(); // read first number from user
	
		System.out.print( "Enter second integer: "); // prompt
		number2 = input.nextInt(); // read first number from user
	
		sum = number1 + number2; // add numbers
	
		System.out.printf( " Sum is %d\n", sum ); // display sum
	
	}
	
}

Regards,
Valentin N

import java.util.Scanner;
        
public class Calculate {

    public static void main( String args[] ) {

        Scanner input = new Scanner ( System.in);

        int number1; // first number
        int number2; // second number
        int number3; // third number    
        int largest; // largest value
        int smallest; // smallest value
        int sum; // sum of numbers
        int product; // product of numbers
        int average; // average of numbers

        System.out.print("Enter first integer:");//Prompt
        number1 = input.nextInt(); //read first number from user

        System.out.print("Enter second integer:");//Prompt
        number2 = input.nextInt(); //read second number from user

        System.out.print("Enter third interger:");//prompt
        number3 = input.nextInt(); //read third number from user

        // Make the number1 as maximum
        largest = number1;
        
        if(largest < number2)
            largest = number2;
        
        if(largest < number3)
            largest = number3;
        
        System.out.println("Maximum is: " + largest);
        
        // Make the number1 as minimum
        smallest = number1;
        
        if(smallest > number2)
            smallest = number2;
        
        if(smallest > number3)
            smallest = number3;
        
        System.out.println("Smallest is: " + smallest);

    } // End of method
} // End of class

maybe this might help, something to compare to I guess

hey all once again :slight_smile:

I am trying to make f(x)=x/0.735kW in java and I have no luck and I can’t see what I am doing wrong or what is missing. The code source code is below



// Vi ska skapa en formel som beskriver hur man många kW som används då x antal HK används.
import java.util.Scanner; // Programmet använder class Scanner

public class HK_till_kW
{
	// 
	public static void main( String args[] )
	{
		// skapar Scanner för att kunna få input från cmd.exe dvs kommandotolken 
		Scanner hästkrafter = new Scanner( System.in );
		
		double antal_HK;
		double HK_kW;  
		double kW;
		
		System.out.print( "Ange antal hästkrafter som ska omvandlas till kW: " ); // Frågar användaren
		antal_HK = hästkrafter.nextDouble(); // Inslagna värdet från användaren
		
		HK_kW = 0.735;
		
		kW = antal_HK / HK_kW ; // De angivna hästkrafter divideras med vad en hästkraft är i kW
		
		System.out.printf( "Resultat är %d\n", kW ); //Resultatet kommer att visas 
		
	}
}