Using Java.util.scanner with command prompt -
i'm trying program run solely out of command line (command prompt in case) when create .jar keep getting error:
expception in thread "main" java.lang.unsupportedclassversionerror: exponentiation: unsupported major.minor version 51.0 @ java.lang.classloader.defineclass1(native method) @ java.lang.classloader.defineclasscond(unknown source) @ java.lang.classloader.defineclass(unknown source) @ java.security.secureclassloader.defineclass(unknown source) @ java.net.urlclassloader.defineclass(unknown source) @ java.net.urlclassloader.access$000(unknown source) @ java.net.urlclassloader$1.run(unknown source) @ java.security.accesscontroller.doprivileged(native method) @ java.net.urlclassloader.findclass(unknown source) @ java.lang.classloader.loadclass(unknown source) @ sun.misc.launcher$appclassloader.loadclass(unknown source) @ java.lang.classloader.loadclass(unknown source) not find main class: exponentiation. program exit.
the program is:
//import scanner user input import java.util.scanner; public class exponentiation { static long values[]; //array of values computed static long output[]; //array of computed values static int numberexp; //number times experiment run static int currentexp = 1; //current time experiment running //main method public static void main(string [] args) { //run initial setup , random generating setup(); //run interative , recursive components until user specified number of experiments (currentexp = 1; currentexp <= numberexp; currentexp++) { iterative(); recursive(); } } //close main method //runs trail iteratively public static void iterative() { //create variables time long initialtime; long endtime; long difftime; //record initial time initialtime = system.nanotime(); //for every value exponetiate (int counter = 1; counter <= values[0]; counter++) { //raise every value opposing value in array output[counter] = values[counter]^values[(int)values[0] + 1 - counter]; } //recourd end time endtime = system.nanotime(); //calculate difference difftime = endtime - initialtime; //output time values system.out.println(); system.out.println("experiment " + currentexp + " iterative:"); system.out.println(initialtime); system.out.println(endtime); system.out.println(difftime); } //close iterative method //runs trial recursively public static void recursive() { //create variables time long initialtime; long endtime; long difftime; //record initial time initialtime = system.nanotime(); //for every value exponetiate (int counter = 1; counter <= values[0]; counter++) { //raise every value opposing value in array using recursive method output[counter] = recursiveexpo(values[counter],values[(int)values[0] + 1 - counter]); } //recourd end time endtime = system.nanotime(); //calculate difference difftime = endtime - initialtime; //output time values system.out.println(); system.out.println("experiment " + currentexp + " recursive:"); system.out.println(initialtime); system.out.println(endtime); system.out.println(difftime); } //close recursive method public static long recursiveexpo(long base, long expo) { if (expo == 0) { return 1; } else { return base * recursiveexpo(base, expo - 1); } } //close recursiveexpo //setup method - runs setup isolated main program public static void setup() { int lowrange; //lowest possible random value int highrange; //highest possible random value int numoftrials; //number of trials/random numbers generated //create scanner user input scanner input = new scanner( system.in ); //runs random number generator until assortment found (boolean goodrandom = false; goodrandom == false;) { //clear values[], in case values = null; system.out.println("this program iterative exponetiation"); system.out.println("enter prefered range of numbers"); system.out.println("lowest possible number"); lowrange = input.nextint(); //store min random number system.out.println("highest possible number"); highrange = input.nextint(); //store max random number system.out.println("number of trials"); numoftrials = input.nextint(); //store number of trials system.out.println("how many times should experiment run?"); numberexp = input.nextint(); //store number of experiments //create array of correct size , store size in 0th element values = new long[numoftrials+1]; values[0] = numoftrials; //make output array same lenght output = new long[numoftrials+1]; //generate random values each element until numoftrials reached (int counter = 1; counter <= numoftrials; counter++) { values[counter] = (int)(math.random()*(highrange)) + lowrange; } //create output , concatinate numbers (int counter = 0; counter <= values[0]; counter++) { //add line break every tenth number //and output values[] if ((int)(counter/10) == (((double)counter)/10)) { system.out.println(values[counter] + " "); } else { system.out.print(values[counter] + " "); } } system.out.println("enter 1 use these values or 0 new ones"); //regenerate or not? if (input.nextint() == 1) { goodrandom = true; //continue on actual test } } //close number-generator loop } //close setup method } //close expo class
i think i'm doing wrong scanner, i'm not sure what.
while youre compiling code jdk 7+ youre running using java <=6. if here you'll see 51.0 java 7, , th fact unsupported means java on classpath older.
try running java -version
on command line verify, , fix path
Comments
Post a Comment