Practice Programs

The 3 problems below represent what you will be doing in class on Wed the 7th. There are other sample programs to try.  I will add more to this list, but you can find them also under the if/while lesson and the method out lesson

int a=7; int b=2;  int c=12;
 while (b < c)
 {
System.out.println("yes" + c);
b++;
if (b>3)
{
System.out.println("more" + b);
if (c < 9)
{
while(a>b)
{
System.out.println("do it" + b);
if (b<6)
{
c--;
System.out.println(c);
if (a==7)
 System.out.println("done");
System.out.println("exit");
b++;
}
a--;
}
a=6;
System.out.println("nope");
}
 System.out.println("stop" + b);
}
if (c<8)
{
System.out.println("junk");
 c-=1;
}
c=c-2;
  }

 

Write a program to get 2 numbers from the user until the first number is more than 10 bigger than the second number. For each pair of numbers entered, tell which one is bigger (first or second..)  If the 2 numbers are the same, get another number from the user and if that number is also the same, tell the user that fact.  When the loop is exited,  give the average of all the first numbers.  Tell what percent of the time the first number was bigger.  Print the highest second number.  Print how many times the 2 numbers were the same.  Print how many times the difference between the 2 numbers was even

   static int a = 3;
   static int b = 5;
   public static void main( String args[] )
   {
         int a=1; int c=2; int d=4;
         System.out.println(a+" "+b+" "+c+" "+d);
         a = first(a,b);
         b = a + c;
         System.out.println(a+" "+b+" "+c+" "+d);
         sec(b);
         System.out.println(a+" "+b+" "+c+" "+d);
   }

   static int first(int c, int d)
   {
         int b = c+1;
         System.out.println(a+" "+b+" "+c+" "+d);
         sec(b);
         a++;
         System.out.println(a+" "+b+" "+c+" "+d);
         return c;
   }

   static void sec(int c)
   {
         b++;
         int d = a;
         System.out.println(a+" "+b+" "+c+" "+d);
   }

Below are some topics we discussed in class. We will not test them for now, but review them and make sure you know and understand the answers.

Diagram a computer

Match  the 6 things a computer can do with the 5 statements you need in Java.     Java:

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
    • Diagram the programming process.
        •  T / F   A computer can do anything you can teach a person to do.

           

          T / F  A computer can learn how to do things on its own.

           

          Describe the limitation of a computer.. What can it NOT do?

           

           

           

            When you write a Java program, it is called a ___________ file and it ends with the  ._____ extension  (.exe…).  This file compiles into a file with the  .______ extension.  This new file must be run with the aid of a(n) ___________________.   If this is found in the browser, the Java program is called a(n) ______________.  If you find the needed program running on the local machine it is called a(n) ______________

           

          Label the parts of a Java class in the box below:

           

          Why does Java not compile directly into an exe file?

           

          What are the 3 skill you need in order to read code?

           1.

           2.

           3.

           

          Which of these is the HARDEST to do?   ______________________

BuiltWithNOF

[Java at Evergreen] [Syllabus] [To Do List] [Lessons/Programs] [Evaluation/Review] [Help] [FAQ/GWIFO] [Discuss/Reports] [Resources] [Readings] [Portfolio] [Instructor]