int i = 3;
int[ ] a = { 45, 21, 97, 38, 90, 77, 62 };
System.out.println(++a[++i]);
System.out.println(a[i--]--);
System.out.println(a[--i]++);
System.out.println(--a[i++]);
System.out.println(a[i] += 2);
Ans:
91 91 97 97 40
Ans: Insertionsort moves up array elements one by one until a slot for the next item to insert into the array is found. SelectionSort swaps the item immediately to the right of the sorted segment with the smallest element of the remaining unsorted elements.
Ans: (1) Import java.io.*, (2) declare the main method header to throw FileNotFoundException, (3) declare and instantiate a Scanner object s from a FileReader object, (3) while s.hasMoreXX (you choose XX) is true use the s.nextXX methods to read data from the file.
FileReader fr = new FileReader("persons.txt");
Scanner s = new Scanner(fr);
Ans:
Scanner s = new Scanner(new FileReader("persons.txt"));
public Card(int theRank, int theSuit, boolean faceShowing)Save this class file to the folder where you are creating your Java file: Card.class
Ans:
public static void main(String[ ] args)
{
Card[ ] deck = new Card[52];
int index = 0;
for(int suit = 1; suit <= 4; suit++)
for(int rank = 2; rank <= 14; rank++)
deck[index++] = new Card(rank, suit, false);
for(index = 0; index <= 51; index++)
System.out.println(deck[index]);
}
import java.io.*;
public static void main(String[ ] args)
throws FileNotFoundException
PrintWriter pw = new PrintWriter("out.txt");
pw.close( );If PrintWriter object is not closed, output will not be written to the output file.
public static void main(String[ ] args)
Ans: Only the main method is given. Be sure to include java.io.* and java.util.Scanner.
public static void main(String[ ] args)
throws FileNotFoundException
{
int x = Double.parseDouble(args[0]);
int y = Double.parseDouble(args[1]);
System.out.println("The sum is " + (x + y));
}
Ans: Only the main method is given. Be sure to include java.io.* and java.util.Scanner.
public static void main(String[ ] args)
throws FileNotFoundException
{
String inputFileName = args[0];
String outputFileName = args[1];
Scanner s = new Scanner(new FileReader(inputFileName));
PrintWriter pw = new PrintWriter(outputFileName);
int x = Integer.parseInt(s.nextInt( ));
int y = Integer.parseInt(s.nextInt( ));
pw.println("The sum is " + (x + y));
pw.close( );
}
> java ToUpper raven.txt raven-upper.txt
Keep track of pending fonts on a webpage.
Keep track of pending methods in a Java program.
Evaluation of postfix expressions.
isFull returns true if the stack is full (contains 200 Person objects) and false otherwise.
getTop returns a reference to the Person object on the top of the stack. It returns a null reference if the stack is empty.
push pushes a Person object onto the top of the stack if the stack is not full. If the stack is full, push does nothing.
pop removes the Person object from the top of the stack if the stack is not empty. If the stack is empty, pop does nothing.
toString returns the contents of the stack as a string.