java code online code example
Example 1: online java code fixer
123456789101112131415161718192021222324import java.util.Scanner;public class LeapYear{ public static void main(String[] args) { int lineCounter = 0; for(int year=101; year <= 2100; year++) { if ((year % 4 == 0)) { System.out.println(year + ""); lineCounter++; { if(lineCounter == 10) } System.out.println(""); lineCounter = 0; } } }}X
Example 2: java editor
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import javax.sound.sampled.*;
public class Main {
public static void main(String[] args) throws UnsupportedAudioFileException, IOException, LineUnavailableException{
Scanner scanner = new Scanner(System.in);
File file = new File("Level_Up.wav");
AudioInputStream audioStream = AudioSystem.getAudioInputStream(file);
Clip clip = AudioSystem.getClip();
clip.open(audioStream);
String response = "";
while(!response.equals("Q")) {
System.out.println("P = play, S = Stop, R = Reset, Q = Quit");
System.out.print("Enter your choice: ");
response = scanner.next();
response = response.toUpperCase();
switch(response) {
case ("P"): clip.start();
break;
case ("S"): clip.stop();
break;
case ("R"): clip.setMicrosecondPosition(0);
break;
case ("Q"): clip.close();
break;
default: System.out.println("Not a valid response");
}
}
System.out.println("Byeeee!");
}
}
Example 3: online java compiler
SandBox: https://codesandbox.io/
Example 4: online java compiler
Repl.it Compiler: click source buttton to go to the website
Pros: You can add files, do javafx and jswing.
Example 5: java compiler
import java.util.Scanner;
public class exercise30 {
public static void main( String[] args ) {
Scanner keyboard = new Scanner(System.in);
int total = 0;
boolean current;«
System.out.print("Type in a bunch of values and I'll add them up. ");
System.out.println("I'll stop when you type a zero.");
while (total += current){
System.out.print("Value: ");
current = keyboard.nextInt();
System.out.println("The total so far is: " + total);
} while ( current != 0 );
System.out.println("The final total is: " + total);
} }