Given 8 distinct integers from the set {1, 2, . . . , 16}, prove that there exists k such that ai aj = k
has at least 3 distinct solutions (ai , aj ) ?
Solution
For any k (unless the K is zero), at least 3 distinct solutions need not be existing.
Let\'s look at the next most favourable case
If k= 2;
We have to consider the case where the number of solutions of ai-aj=2 are minimum since we
have to show that at least 3 distinct solutions exist (which means even in the most unfavourable
case for a chosen k there will be 3 distinct solutions satisfying the equation ai-aj=2)
If k = 2; we start by taking numbers that are not at all 2 units apart from each other;
So we start with 1 and move 3 units successively ahead
1, 4, 7, 10,13, 16; Now we notice that these 6 numbers are of 3k+1 form; remaining numbers
can be any 2 ranomdly selected say 2 and 11; we get 4-2 = 2 and 13-11=2; Hence only 2 distinct
solutions are possible..
Hi, I need help with a java programming project. specifically practi.pdf
1. Hi, I need help with a java programming project. specifically practice Program number 2 on page
809 from chapter 10 of the 7th edition of the book , java:an introduction to problem solving and
programming. it tells me to Write a program that reads a file of number of type int and outputs
all the numbers to another file, but without
any duplicate numbers. Assume that the input file is sorted from smallest first to largest last.
After
the program is run, the new file will contain all the numbers in the original file, but no number
will appear more than
once in the file. The numbers in the output file should also be sorted from smallest to largest.
Your program
should obtain both file names from the user. For the text-file version, the file should be a text
file with one number
per line. For the binary-file version, the file should be binary file that consists entirely of
numbers of type int
that were written using writeInt.
I have written a program that technically runs , but i cant get it to create an output file that
displays the needed numbers.
Here is my code
import java.lang.*;
import java.io.*; ///required packages
import java.util.*;
public class RemoveDuplicate
{
public static void main (String args []) throws Exception
{
int count = 0;
String line;
String newLine = System.getProperty("line.seperator"); //gets line seperator for system
System.out.print(" enter input file name"); // taking original file name from user
Scanner scanner = new Scanner(System.in);
2. String fileNameOld = scanner.next(); //reads original file name
System.out.print(" enter output file name"); // takes name of new file from user
String fileNameNew = scanner.next();
File file = new File (fileNameNew); // creates file object
PrintWriter out = new PrintWriter (new FileWriter(file)); //creates printwriter object
Scanner scanFile = new Scanner (new File(fileNameOld)); //creates scanner object for reading
file
int temp = 0;
while(scanFile.hasNextLine()) // while numbers are in file
{
line = scanFile.nextLine(); // reads number
int number = Integer.parseInt(line);// converts numbers to int value
if(count == 0)
{
out.write(Integer.toString(number));
out.write(newLine);
temp = number;
count ++ ; //increment count
}
else
3. {
if (temp != number)
{
out.write(Integer.toString(number));
out.write(newLine);
temp = number;
}
}
}
out.close(); // closes stream
}
}
For reference I need to make it read an input txt/notepad file called numbers.txt which has
numbers that look like following
and get it to produce an output file called output.txt, which looks like the following
Any help would immensly be appreciated. 12 33 33 178 239 1254 11245 x https://bb courses n x
f Facebook x C Chegg Study IGuid X Hi, I Need Help Wit x C https://bb.courses.main /courses
/1/1710. UMS03-C.0006 1/content/ 1873037 1/numbers.txt e.edu OM x D HMWK7 Screenshot
x 5:34 PM 11/28/2016
Solution
RemoveDuplicate.java
import java.lang.*;
import java.io.*; ///required packages
import java.util.*;
public class RemoveDuplicate
{
public static void main (String args []) throws Exception
{
int count = 0;
String line;
4. String newLine = System.getProperty("line.seperator"); //gets line seperator for system
System.out.print(" enter input file name"); // taking original file name from user
Scanner scanner = new Scanner(System.in);
String fileNameOld = scanner.next(); //reads original file name
System.out.print(" enter output file name"); // takes name of new file from user
String fileNameNew = scanner.next();
File file = new File (fileNameNew); // creates file object
PrintWriter out = new PrintWriter (new FileWriter(file)); //creates printwriter object
Scanner scanFile = new Scanner (new File(fileNameOld)); //creates scanner object for reading
file
int temp = 0;
while(scanFile.hasNextLine()) // while numbers are in file
{
line = scanFile.nextLine(); // reads number
int number = Integer.parseInt(line);// converts numbers to int value
if(count == 0)
{
out.write(Integer.toString(number));
out.write(" ");