1 private void main(String args)
4 private void RepeatSentence(String sentenceToRepeat; int n)
2 {
3    
RepeatSentence("I will eat my spinach.", 20);
5    
for(i = 1; i <= 20; i =+ 1);
6    
{
7       
System.println(sentenceToRepeat);
8    
}
9 }
In Line 3, RepeatSentence should start with a lower case r.
There should be a closing brace } between lines 3 and 4.
In Line 4, repeatSentence should be static. There should also be a comma, not a
semicolon between String sentenceToRepeat and int n.
An opening brace should be between lines 4 and 5.
The variable i must be declared, either in the for statement or between lines 4 and 5.
The for loop should go from 1 to n, not 1 to 20.
In Line 5, i =+ 1 should be i += 1, or better yet, i++. There should be no ; at the
end of Line 5.
In Line 7, System.println should be System.out.println.
Answer:
public class Time
      
f = new DecimalFormat("00");
import cs1.Keyboard;
import java.text.DecimalFormat;
{
   
public static void main(String[] args)
   
{
      
int h, m, s;
      
String h2, m2, s2;
      
DecimalFormat f;
      
h = Keyboard.readInt();
      
m = Keyboard.readInt();
      
s = Keyboard.readInt();
      
h2 = f.format(h);
      
m2 = f.format(m);
      
s2 = f.format(s);
      
System.out.println(h2 + ":" + m2 + ":" + s2);
   
}
}
Answer:
public class Circle extends Applet
import java.applet.Applet;
import fava.awt.*;
{
   
public void init()
   
{
      
setSize(300, 300);
   
}
   
public void paint(Graphics g)
   
{
      
g.drawOval(50, 100, 100, 100);
   
}
}
The toString method is also a method of the Object class that can be overridden. By default, toString prints the name of the object and its location in memory. Usually a more useful action for toString to take is to print some information about the contents of the object.
Conclusion: use a.equals(b) for String objects, not a == b.
Here is a diagram showing this situation:
The signature for the first constructor is (   ).
The accessor methods for Kid are getName, getId, getGender, getAge. There are no mutator methods, so the private instance variables name, id, gender, and age are read only.
The other methods for Kid are hasBirthday (adds 1 to age) and print.
Syntax 1:
int[] a;
a = new int[3];
a[0] = 32; a[1] = 18; a[2] = 70;
int[] a = new int[3];
a[0] = 32; a[1] = 18; a[2] = 70;
int[] a = {32, 18, 70};
The methods are top (returns the value of the top elements), push (push a new element onto the top of the stack), pop (remove the top element of the stack), isEmpty (returns true is the stack is empty), and isFull (returns true if the stack is full).
These methods behave like virtual methods in C++: the method called does not depend on the type of the reference variable, it depends on call to new that created the object.
Creating a class that displays an applet with controls consists of these steps: