You are on page 1of 2

Lorenzo Sukhdeo

September 27, 2013


CS 115-01
Jessi
Lab 5
5.
Enter an int >
Hello
Enter an int >
Hello
Enter an int >

6.
Hello
Enter an int >
Hello
Enter an int >
Hello
Enter an int >

7.
Enter an int >
Enter an int >
Hello
Enter an int >
Hello

8. i=10 and sum = 34

30. infinite loop.

32. there is a semicolon after the parenthesis of the for statement. Delete that semicolon!

33. infinite loop. this loop will keep going because it won’t stop because 10 and any number greater
than 10 will always be greater than 0. You should change 10 to 19, then the loop will fall out whenever i
is 19 or greater! Because we only want hello printed 10 times.

45.
import java.util.Scanner;
public class MyProgram
{
public static void main (String[] args)
{
Scanner scan = new Scanner( System.in);
System.out.print("Enter how many doubles how many wanted: ");
double i = scan.nextDouble();
double c= 0;

for (int z=1; z<=i; z++)


{
Lorenzo Sukhdeo
September 27, 2013
CS 115-01
Jessi
System.out.print("Enter a double: ");
double m= scan.nextDouble();
c= m+c;

}
System.out.println("The average value is: " + (c/i));
}
}

49.
import java.util.Scanner;
public class HelloWorld
{
public static void main (String[] args)
{
Scanner scan = new Scanner( System.in);
System.out.println("Enter a number as a integer");
int n = scan.nextInt();

for(int i=0; i<n; i++)


System.out.println("Hello World");
}
}

52.
import java.util.Scanner;
public class MyProgram
{
public static void main (String[] args)
{
Scanner scan = new Scanner( System.in);
System.out.print("Enter an integer: ");
int n = scan.nextInt();

for (int i=0; i<9; i++)


{
System.out.print("Enter an integer: ");
int m= scan.nextInt();

if (m<n)
n=m;

}
System.out.println("The minumum value is: " + n);
}
}

You might also like