I need to find the largest value in a scanned file.I've gotten the count, sum, average, evens, and odds myself.The code above the while loop is not mine and my professor said I may no edit it or other wise mess with it. I also may not use arrays.Also I've realized that the largest/smallest are recording the value of count. I've tried the following:
Scanner infile = new Scanner ( new FileReader(args[0]) );
int count=0,sum=0, largest=Integer.MIN_VALUE,smallest=Integer.MAX_VALUE, evens=0, odds=0;
double average=0.0;
I am trying to find 3 largest numbers in an array using a single For loop but my following code is still showing randomly sorted numbers.
public class largest3 { static int m, n, o; static int array[] = new int[100]; public static void main(String[] args) { for (int i = 0; i < 10; i++) { array[i] = (int) (Math.random() * 100);
Write a program that finds both the largest and smallest of several integers. T. For example, a program that determines the winner and loser of a sales contest would input the number of units sold by each salesperson. The salesperson who sells the most units wins the contest; the salesperson who sells the least units loses the contest. Write a pseudocode program, then a Java program that inputs a series of 10 integers and determines and prints the largest integer and the smallest integer. Your program should use at least the following four variables: counter, number , largest and smallest. After i run the code i just get the largest input without the smallest .
This is my code :
import java.util.Scanner; // program uses scanner // main Class begins public class Largest12 { public static void main(String[] args) //main method begins { //Initial variables int counter = 0; // initiate counter int number=0 ;
I think the problem in this is that the variable max is initialised as 0. Afterwards it remains in the while loop only, so the output is always 0. I dont know how to bring the last max value out of loop and print it.
I have to get the user to enter in 10 numbers and with those 10 numbers I have to find the total, average, smallest, largest numbers in the set the user inputs. I have the total and average already figured out but how would you go about trying to find the largest and smallest numbers within this set of code.
import java.util.*; public class testhw7 { public static void main (String [] args) { Scannernumberin = new Scanner (System.in); doublevalue[]; doubletotal;
I tried to create file and write the output of my program in it in java when i use WriteLong then the file does not contain long value, how I create this file my program is to print prime numbers between 500000 to 10000000
public class primenumber { public static void main(String[] args) { long start = 5000000; long end = 10000000; System.out.println("List of prime numbers between " + start + " and " + end); for (long i = start; i <= end; i++) { if (isPrime(i)) { System.out.println(i);
Within tomcat "webapps" directory, have lots of scanned PDF files (size in KB and MB).Using Java and JSP, I want to search for any user entered text in these scanned PDF files.The result must display the name of those PDF files which has that entered text.
I have to write a program that find the sum of two numbers 62 and 99 and stores them in a variable named total. However, I have one error that I just can't get rid of and can't tell what it is. I'm using jGrasp and here's what it says:
Programming Challenge #5.java:14: error: class SumofTwoNumbs is public, should be declared in a file named SumofTwoNumbs.java public class SumofTwoNumbs { ^ 1 error ----jGRASP wedge2: exit code for process is 1. ----jGRASP: operation complete.
and here: is my code:
import java.util.Scanner; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** // This program has variable of several of the integer types. public class SumofTwoNumbs { public static void main(String[] args) {
im trying to do a program to find if numbers are consecutive or not! if they are consecutive i need a true as a return and a false when they are not... i did this program and im sure i did something wrong because i keep only true returns ..
Example: (3,5,7) (1,2,2) (7,7,9) should return a false! Java Code: import java.util.*; public class Consecutive{ public static void main (String [] args){ Scanner console= new Scanner(System.in); System.out.println("Enter three numbers"); String numbers = console.nextLine(); System.out.println( "The numbers (" + numbers + ") is '" + consecutive( numbers ) + "'" ); }//end of main
The program below is intended to find the arithmetic mean of the numbers stored in the array q in two ways: once by storing the numbers in an ArrayList d, where you allow all the necessary conversions to be performed automatically; and once by storing them in an ArrayList e, where you perform all the conversions by hand. Complete the program.
Here is what I have so far:
double[] q = { 0.5, 2.4, 7.4, 2.8, -6.2 }; ArrayList<Double> d = new ArrayList<Double>(); ArrayList<Double> e = new ArrayList<Double>(); for ( double x : q ) { d.add( x ); e.add ( new Double ( x ) );
[Code] .....
Why does it still show "a / d.size?" I thought I fixed that. Whatever, it's supposed to be "dTotal / d.size()", etc.
public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println(" Enter the maximum number "); int maxNumber = scanner.nextInt(); int[]numberList = createList (maxNumber);
[code]....
I have a problem with the output. It only get as far as marking the multiples of 2. It does not mark the multiples of 3 and so on.Example output: If the range is from 2 to 15 the output is :2, 3, 0, 5, 0, 7, 0, 9, 0, 11, 0, 13, 0, 15 note: 0 means its marked.As you can see it only marks multiples of 2 but it does not mark multiples of 3 above. I think the problem lies in the for loop inside my main method, because the index does not increment.
import java.util.Scanner; public class AvgLrgSml{ public static void main(String[]args){ System.out.print("Hello there. Please enter any three numbers."); Scanner keyboard = new Scanner(System.in); double num1 = keyboard.nextDouble(); double num2 = keyboard.nextDouble();
depth is a variable for the row in the triangle. My problem is that i need the solution to be recursive and i am having trouble doing this. So far i have
public static int findMax(int[][] array,int depth) { if (depth==0) return array[0][0]; else if }
I want to find the prime palindrome numbers less that a given number by my program. Here is my code, I am trying to find the method to solve the errors when I compile it. It said variable a might not have been initialized in line 41,62,86.
import java.util.Scanner; public class Lab5{ public static void main (String[] args){ System.out.println("Please input a number"); Scanner Input=new Scanner(System.in); int num = Input.nextInt();
I am trying to write a code that asks the user to input ten numbers and then finds and displays the smallest number out of the ones given. I am supposed to implement arrays into the program to do this. But the problem I have run into is that when I compile the code in jgrasp, I am given several error messages and I am not quite sure what I have done wrong. I'm assuming it is either a syntax or a logical error on my part but reading over the code I do not understand what is causing these errors.
This is the most current draft of my code:
import java.util.Scanner; public class Exercise7_9 { public static void main(String[] args) { double[] numbers = new double[10]; //Enter ten double numbers: Scanner(System.in) java.util.Scanner input = new java.util.Scanner(System.in); System.out.println("Please enter ten numbers: ");
[Code] ....
/* Sample Run: Enter ten numbers: 1.9, 2.5, 3.7, 2, 1.5, 6, 3, 4, 5, 2 */
And these are the exact error messages:
----jGRASP exec: javac -g Exercise7_9.java Exercise7_9.java:35: error: '.class' expected if (double m > list[i]) { ^ Exercise7_9.java:35: error: illegal start of expression if (double m > list[i]) {
the prime numbers from 1 to 2500 can be obtained as follows. From a list of the numbers of 1 to 2500,cross out al multiples of 2 (but not 2 itself). Then, find the next number (n, say) that is not crossed out and cross out all multiples of n (but not including n).
Repeat this last step provided that n has not exceeded 50 (the square root of 2500). The numbers remaining in the list (except 1) are prime. Write a program which uses this method to print all primes from 1 to 2500. Store your output in a file called primes.out.
I'm getting this -file not found- error despite the fact that I have saved the file with appropriate permissions in the src folder of the given application in netbeans. The program prompts for a listings.txt file to read and write data to a new file that counts and sums the info in a overview.txt report. Here is the stacktrace:
run:
Type in the name of the file: listings There was a problem:java.io.FileNotFoundException: listings.txt (The system cannot find the file specified) java.io.FileNotFoundException: listings.txt (The system cannot find the file specified) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(FileInputStream.java:131) at java.io.FileInputStream.<init>(FileInputStream.java:87) at java.io.FileReader.<init>(FileReader.java:58) at kettask2a.KetTask2a.main(KetTask2a.java:48)